Metro 遇到错误:尝试解析module“firebase”时

IT技术 reactjs firebase react-native firebase-authentication node-modules
2022-07-11 01:24:27

我在启动模拟器后遇到了这个错误,我在终端上的图像和错误下添加了我的代码。这是我在模拟器上的 App.js 文件 错误图像

错误:错误:尝试firebase从文件解析module时,成功找到/Users/capcapbakkal/Desktop/RNKurs/identifyVerification/index.js了包。/Users/capcapbakkal/Desktop/RNKurs/identifyVerification/node_modules/firebase/package.json但是,这个包本身指定了一个main无法解析的module字段(/Users/capcapbakkal/Desktop/RNKurs/identifyVerification/node_modules/firebase/index。事实上,这些文件都不存在:

import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';

componentDidMount() {
    const firebaseApp = initializeApp({
      apiKey: "AIzaSyCpM2dwcUvJqVaKz856hz",
      authDomain: "authentication-b4",
      projectId: "authen",
      storageBucket: "authenticat",
      messagingSenderId: "7532",
      appId: "1:753222",
      measurementId: "G-"
    });// I changed this, it isn't wrong

  }
2个回答

我在使用 expo 构建 React Native 应用程序时遇到了同样的问题

//package.json

"expo": "^44.0.0",
"firebase": "^9.8.1",
Metro has encountered an error: While trying to resolve module `idb` from file `/Users/cerebra/workspace/retailshake/recognizeReborn/node_modules/@firebase/app/dist/esm/index.esm2017.js`, the package `/Users/cerebra/workspace/retailshake/recognizeReborn/node_modules/idb/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/cerebra/workspace/retailshake/recognizeReborn/node_modules/idb/build/index.cjs`. Indeed, none of these files exist:

修复了降级的firebase

//package.json

"firebase": "9.7.0",

我遇到了同样的问题,我将 Firebase 版本从 9.6.8 降级到 8.2.3,它对我有用。

这是一个可能有用的参考。

https://github.com/expo/expo-cli/issues/3066