34
import firebase from 'firebase'
 
const firebaseConfig = {
  apiKey: "AIzaSyBOK7x5N5UnjY4TDqndzH7l5tvdNIsWFRc",
  authDomain: "todo-app-e3cf0.firebaseapp.com",
  projectId: "todo-app-e3cf0",
  storageBucket: "todo-app-e3cf0.appspot.com",
  messagingSenderId: "940016886081",
  appId: "1:940016886081:web:91686613f16b1b1f8001c0",
  measurementId: "G-JHPC7TP12K"
};
  
const firebaseApp = firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
  
export default db;

Error Module not found: Error: Package path . is not exported from package C:\Users\Sairam\Visual Code\todo-list\node_modules\firebase (see exports field in C:\Users\Sairam\Visual Code\todo-list\node_modules\firebase\package.json) Did you mean './firebase'?

Sairam S
  • 347
  • 1
  • 3
  • 4

10 Answers10

63

I believe the firebase had lot of updates recently, so you should update the imports this way and it worked liked a charm.

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

const firebaseConfig = {
  apiKey: "AIzaSyBOK7x5N5UnjY4TDqndzH7l5tvdNIsWFRc",
  authDomain: "todo-app-e3cf0.firebaseapp.com",
  projectId: "todo-app-e3cf0",
  storageBucket: "todo-app-e3cf0.appspot.com",
  messagingSenderId: "940016886081",
  appId: "1:940016886081:web:91686613f16b1b1f8001c0",
  measurementId: "G-JHPC7TP12K"
};

// 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 };
Kesava Karri
  • 910
  • 8
  • 11
7

You should import like below. I see this from the firebase documentation: https://www.npmjs.com/package/firebase

import { initializeApp } from "firebase/app";
import { getFirestore } from 'firebase/firestore/lite';

const firebaseConfig = {
  apiKey: "AIzaSyBOK7x5N5UnjY4TDqndzH7l5tvdNIsWFRc",
  authDomain: "todo-app-e3cf0.firebaseapp.com",
  projectId: "todo-app-e3cf0",
  storageBucket: "todo-app-e3cf0.appspot.com",
  messagingSenderId: "940016886081",
  appId: "1:940016886081:web:91686613f16b1b1f8001c0",
  measurementId: "G-JHPC7TP12K"
};

const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);

export default db;
msefer
  • 331
  • 2
  • 10
7

In your Firebase config file, set up Firebase as follows:

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

// Your web app's Firebase configuration
const config = {
  //your config json file
};


firebase.initializeApp(config);

export const firestore = firebase.firestore();


export default firebase;

In the relevant .js script import Firestore and Firebase as follows:

import {firestore as db}  from './firebase-config' 
import firebase from './firebase-config';
Laurel
  • 5,965
  • 14
  • 31
  • 57
Riolite
  • 101
  • 1
  • 7
6

If you use electron-react-boilerplate, in webpack.config.renderer.dev.dll.ts, remove firebase from the entry point. For example:

  entry: {
    renderer: Object.keys(dependencies || {}).filter((it) => it !== 'firebase'),
  },
asdacap
  • 738
  • 2
  • 9
  • 15
  • Bonus for stating the exact file to modify instead of just saying add a webpack setting. Worked fo me. – Glenn Jul 17 '22 at 00:23
3

It is not working because you are using Firebase version-8 codes in upgraded Firebase version-9 , so if you want to solve your problem you should install Firebase version-8 by using the code below:

npm i firebase@8.2.3

  • 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](/help/how-to-answer). – Community Jun 21 '22 at 17:36
2

I noticed that I was importing my firebase.ts config file as import db from "firebase" (absolute imports)

The issue here was that webpack was referencing the "firebase" from node_modules, rather than from my firebase.ts. And that's why it threw that error.

I fixed it by importing my firebase configs as import db from "../../firebase", and that worked

adedaniel
  • 41
  • 4
0

You have mistaken at const db = firebase.firestore();

It should be const db = firebaseApp.firestore();

Even after doing that you will get error of module not found. You need to import as following

import firebase from 'firebase/compat/app';

import 'firebase/compat/firestore';

This worked for me as I had the same issue!!

Neel gorasiya
  • 155
  • 1
  • 8
0

maybe i meeted the same problem when using webpack. i solved the problem by setting webpack/configuration/resolve/#resolveconditionnames

0

As in v-9.8.2. Here is the docs link

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getStorage } from "firebase/storage";
import { getFirestore } from "firebase/firestore";
import { getDatabase } from "firebase/database";

const firebaseConfig = {};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
export const firebaseAuth = getAuth(app);
export const fbDatabase = getDatabase(app);
export const fStore = getFirestore(app);
export const fStorage = getStorage(app);
Tofazzal haque
  • 544
  • 4
  • 10
0

Currently, Firebase provides two Web SDK variants. So make sure that you are using the correct version of firebase library. With version 9 firebase library was arranged independent libraries. Your syntax is using firebase version 8. version-8 version-9

Ozay Duman
  • 447
  • 3
  • 6