![](/img/trans.png)
[英]Firebase Error : Module not found: Error: Package path . is not exported from package
[英]ERROR in ./src/firebase.config.js 6:0-53 Module not found: Error: Package path ./getFirestore is not exported from package
我正在学习教程,但我不确定问题出在哪里,当我尝试import { db } from '../firebase.config'
时,我一直收到错误消息。
我已经尝试了所有方法并查看了 git 中的教程代码,它们是相同的,所以我认为问题是新的。
这是我尝试导入db
的firebase.config.js
文件和SignUp.jsx
文件。
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
import { getFirestore} from 'firebase/getFirestore';
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: ****,
authDomain:****
projectId: ****",
storageBucket: ****,
messagingSenderId: ****,
appId: ****,
measurementId: ****
};
// Initialize Firebase
initializeApp(firebaseConfig)
const app = initializeApp(firebaseConfig);
const analytics = getFirestore();
const db = getFirestore()
export default db;
import React from 'react'
import { useRef, useState, useEffect } from 'react';
import {Link, useNavigate} from 'react-router-dom'
import {faCheck, faTimes, faInForCircle } from '@fortawesome/free-solid-svg-icons';
import { fontAwesomeIcon } from '@fortawesome/react-fontawesome'
import {
getAuth,
createUserWithEmailAndPassword,
updateProfile
} from 'firebase/auth';
import { db } from '../firebase.config';
您正在默认导出数据库,以使其以这种方式导出:
firebase.config
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
import { getFirestore} from 'firebase/getFirestore';
const firebaseConfig = {
apiKey: ****,
authDomain:****
projectId: ****,
storageBucket: ****,
messagingSenderId: ****,
appId: ****,
measurementId: ****
};
// Initialize Firebase
initializeApp(firebaseConfig)
const app = initializeApp(firebaseConfig);
const analytics = getFirestore();
const db = getFirestore()
// THIS WAY
export {app, db, analytics};
然后在你的文件上你可以这样导入
// HERE IM SHOWING MORE THAN JUST IMPORT THE DB, BUT YOU CAN IMPORT JUST WHAT YOU WANT
import {app, db, analytics} from "./firebase.config"
我发现了我的问题。
它import {getFirestore} from "firebase/firestore";
而不是import { getFirestore} from 'firebase/getFirestore';
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.