Expo Firebase身份验证 "尝试从文件解析模块`idb`"

15

这是我的第一个应用程序。我正在尝试使用Firebase进行电子邮件/密码认证。我按照基本教程https://firebase.google.com/docs/auth/web/password-auth#web-version-9操作,但我一直收到以下错误:

While trying to resolve module `idb` from file '.../node_modules/@firebase/app/dist/esm/index.esm2017.js', the package `/Users/##/##/##/node_modules/idb/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/##/##/##/node_modules/idb/build/index.cjs`. 

我已将此添加到 metro.config.js 文件中:

  resolver: {
    sourceExts: ['jsx', 'js', 'ts', 'tsx', 'cjs'],
  },

问题仍然存在。


1
我遇到了完全相同的问题 ["firebase": "^9.7.0", "react-native": "0.68.1","expo": "^45.0.0"]。 - Eduardo Oviedo Blanco
我也遇到了同样的错误。"expo: ~45.0.0", "firebase: ^9.8.1" - Four
2个回答

28
为解决此问题,请在项目根目录中创建一个名为 metro.config.js 的文件。在该文件中添加文件扩展名 cjs详情
const { getDefaultConfig } = require("@expo/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.resolver.assetExts.push("cjs");

module.exports = defaultConfig;

截图


2
很棒的答案!对我有用。 - Alex Mckay
1
太棒了,这对我也起作用了! - Wibo Kuipers
谢谢,所有其他尝试都失败了。 - polar
2
@polar 你在使用expo吗?配置好metro之后,你可以通过expo start --android --clear来清除缓存,或者尝试删除node_modules并重新安装包。这应该可以解决问题。 - Sohel Islam Imran

6

在创建一个干净的项目并添加Firebase时,我遇到了相同的错误。我认为最新版本的Firebase可能存在一些问题,因此我将其降级为9.6.11以暂时解决该问题。希望他们能尽快解决这个问题...

npm uninstall firebase
npm install firebase@9.6.11

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接