简体   繁体   中英

Module not found: Error: Package path . is not exported from package

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'?

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 };

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;

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'),
  },

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';

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!!

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

for more info:- https://www.npmjs.com/package/firebase

its working Thanks

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

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

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);

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM