最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Module not found: Can't resolve 'firebase' in react js - Stack Overflow

programmeradmin0浏览0评论

In my reactjs project I have installed firebase using 'npm i firebase'. And inside of src folder I have created firebase.js file for firebase config.

import firebase from 'firebase'

const firebaseConfig = {
  apiKey: "******",
  authDomain: "****",
  projectId: "***",
  storageBucket: "*****",
  messagingSenderId: "****",
  appId: "****"
};

firebase.initializeApp(config);

export default firebase

Even after installing firebase in my project. It gives error:

./src/firebase.js
Module not found: Can't resolve 'firebase' in '/home/rupak/Projects/web/firebasereact/src'

Can anyone find the problem?

In my reactjs project I have installed firebase using 'npm i firebase'. And inside of src folder I have created firebase.js file for firebase config.

import firebase from 'firebase'

const firebaseConfig = {
  apiKey: "******",
  authDomain: "****",
  projectId: "***",
  storageBucket: "*****",
  messagingSenderId: "****",
  appId: "****"
};

firebase.initializeApp(config);

export default firebase

Even after installing firebase in my project. It gives error:

./src/firebase.js
Module not found: Can't resolve 'firebase' in '/home/rupak/Projects/web/firebasereact/src'

Can anyone find the problem?

Share Improve this question asked Sep 7, 2021 at 17:30 RupakRupak 5418 silver badges18 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 3

You are not using the new Modular syntax. You can keep using existing code by changing the imports to pat version:

import firebase from 'firebase/pat/app'
import 'firebase/firestore'
// import 'firebase/[SERVICE_NAME]'

However, I'd remend upgrading to the new Modular SDK, which offers some benefits with tree-shaking. Checkout this Firecast for detailed information:

Getting started with Firebase for Web

Refer Firebase docs if you are using newer version initializeApp is moved to firebase/app package

Hey I had the same situation stated above... But by applying this:

import firebase from 'firebase/pat/app'
import 'firebase/firestore'
// import 'firebase/[SERVICE_NAME]'
//export
export const auth = firebase.auth();
export const googleAuthProvider = new firebase.auth.GoogleAuthProvider();

I only removed the (/app), and it worked... THANK YOU

I have faced the same issue, It seems firebase 9.17.0 just dropped.

Rolling back to the 9.16.0 solved the problem.

for yarn package:

yarn add [email protected]

for npm:

 npm i [email protected]

Now check your package.json file looks like this.

"firebase": "9.16.0",

1-npm uninstall firebase or yarn remove firebase

2-npm cache clean or yarn cache clean

3-npm install firebase or yarn add firebase

Perform step 2 cautiously

发布评论

评论列表(0)

  1. 暂无评论