![](/img/trans.png)
[英]Firebase Error : Module not found: Error: Package path . is not exported from package
[英]Firebase Error : Module not found: Error: Package path . is not exported from package
我試圖在我的 React.JS 應用程序上實現 Firebase 以進行身份驗證。 但是,我不斷收到此錯誤
./src/Pages/UserPage/contexts/AuthContext.js 8:0-32 中的錯誤
找不到模塊:錯誤:Package 路徑。 未從 package /Users/Aarnav/Desktop/JavaScript/my-app 副本 2/node_modules/firebase 導出(請參閱 /Users/Aarnav/Desktop/JavaScript/my-app 副本 2/node_modules/firebase/package.json 中的導出字段)
我的 firebase 設置如下所示,
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
const firebaseConfig = {
apiKey: "AIzaSyCPSbjZ9F1TgI43T0SH68rUi9TMHBXRw - s",
authDomain: "csia-41409.firebaseapp.com",
databaseURL: "https://csia-41409-default-rtdb.firebaseio.com",
projectId: "csia-41409",
storageBucket: "csia-41409.appspot.com",
messagingSenderId: "714268776254",
appId: "1:714268776254:web:93d9ef26a5d9c7d7f8be6f",
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth();
我的 authcontext 看起來
import React, { useContext, useState, useEffect } from "react"
import { auth } from "firebase";
const AuthContext = React.createContext();
export function useAuth() {
return useContext(AuthContext);
}
export function AuthProvider({ children }) {
const [currentUser, setCurrentUser] = useState();
const [loading, setLoading] = useState(true);
function signup(email, password) {
return auth.createUserWithEmailAndPassword(email, password);
}
function login(email, password) {
return auth.signInWithEmailAndPassword(email, password);
}
useEffect(() => {
const unsubscribe = auth.onAuthStateChanged((user) => {
setCurrentUser(user);
setLoading(false);
});
return unsubscribe;
}, []);
auth.onAuthStateChanged((user) => {
setCurrentUser(user);
});
const value = {
currentUser,
login,
signup,
};
return (
<AuthContext.Provider value={value}>
{!loading && children}
</AuthContext.Provider>
);
}
同樣出於某種原因,無論我在哪個路由器(頁面)上,我的整個網站都是空白屏幕。 我相信這是因為上面提到的錯誤,但我不確定。
起初我以為是因為我使用的是 firebase 版本 9.14,但是,我更新了 firebase 的設置,但沒有用,錯誤仍然存在。 我不知道如何消除錯誤。
在firebase V9中,您需要使用email和密碼進行注冊和登錄:
import { createUserWithEmailAndPassword, getAuth, signInWithEmailAndPassword } from "firebase/auth";
const auth = getAuth();
function signup(email, password) {
return createUserWithEmailAndPassword(auth, email, password);
}
function login(email, password) {
return signInWithEmailAndPassword(auth, email, password);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.