9

After: npm i firebase

I'am importing firebase from firebase itself & not from a file

import firebase from 'firebase'; >in firebase.js file<

error in terminal>> ./src/firebase.js Module not found: Can't resolve 'firebase' in 'C:\Users\Home\Documents\dsn\e\Documents..........'

4
  • 1
    Try importing firebase using import firebase from 'firebase/app'; and importing the relative firebase modules as needed. Commented Sep 3, 2021 at 11:51
  • it dosen't work. it' ll say there is no default export in the particular folder. Commented Sep 4, 2021 at 8:02
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Sep 7, 2021 at 11:41
  • Can you clarify the quoted text (the type of import?) Commented Apr 16, 2022 at 5:03

4 Answers 4

33

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

Sign up to request clarification or add additional context in comments.

1 Comment

I' am already updated to v9 and "firebase/compact/app" do worked for me.✔
2

There should be no reason to downgrade to version 8 as version 9 provides a fully backward compatible import if you prefix the module import path with "compat".

To use:

import firebase from "firebase/compat/app"; // Other libraries might need to also be prefixed with "compat": import "firebase/compat/auth"; // Then you can then use the old interface, with version 9: if (!firebase.apps.length) { firebase.initializeApp(clientCredentials); } 

Upgrade notes: https://firebase.google.com/docs/web/modular-upgrade

Comments

1

Recent versions of firebase have many changes, use this ->

import firebase from 'firebase/compat/app'; import 'firebase/compat/auth'; import 'firebase/compat/firestore'; const firebaseConfig = { .... }; // Use this to initialize the firebase App const firebaseApp =firebase.initializeApp(firebaseConfig); // Use these for db & auth const db = firebaseApp.firestore(); const auth = firebase.auth(); export { auth, db }; 

Comments

0

initializeApp is moved to firebase/app package in latetst version
so import from firebase/app.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.