TanjimSafat
TanjimSafat

Reputation: 11

Module not found: Error: Can't resolve '@firebase/firestore

I'm trying to connect firebase from my react app. I have installed & reinstalled firebase by npm install firebase. But still getting error:

**Module not found: Error: Can't resolve '@firebase/firestore ' in 'C:\Users\LENOVO\Desktop\crud_firebase\src' **

What should I do now ? How should I conncet to firebase?

I have reinstalled firebase with npm install firebase I have deleted all the modules & ran npm install But still getting the same error. My firebase version is "firebase": "^9.15.0".

Upvotes: 1

Views: 428

Answers (1)

banbz
banbz

Reputation: 31

npm i firebase now installs v9 Modular SDK so you cannot used the old imports. Try refactoring your code to this:

import { initializeApp } from 'firebase/app';

const firebaseConfig = {
  //...
};

const app = initializeApp(firebaseConfig);

If you want to use older syntax then change your imports to compat libraries:

import firebase from "firebase/compat/app"
import "firebase/compat/auth"
import "firebase/compat/firestore"
// other services is needed

You can read more about it in the documentation.

Upvotes: 2

Related Questions