'Metro has encountered an error: While trying to resolve module 'firebase'
I took this error after I started the emulator, I add my codes under the image and error on the terminal. This is my App.js file Error Image on Emulator
error: Error: While trying to resolve module
firebasefrom file/Users/capcapbakkal/Desktop/RNKurs/identifyVerification/index.js, the package/Users/capcapbakkal/Desktop/RNKurs/identifyVerification/node_modules/firebase/package.jsonwas successfully found. However, this package itself specifies amainmodule field that could not be resolved (/Users/capcapbakkal/Desktop/RNKurs/identifyVerification/node_modules/firebase/index. Indeed, none of these files exist:
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
and
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
}
Solution 1:[1]
I had this same issue, I downgraded the Firebase version from 9.6.8 to 8.2.3 and it worked for me.
Here is a reference that could be helpful.
Solution 2:[2]
I encountered the same issue with my React Native app build with expo
//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:
fixed with downgrading firebase
//package.json
"firebase": "9.7.0",
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nathali Aguayo |
| Solution 2 | David Leuliette |
