找不到模块:包路径.未从包中导出



ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

在尝试连接Firebase时,我的代码中出现了以下错误。

文件:firebase.js

代码:

import * as firebase from "firebase"
const firebaseConfig = {
apiKey: "***",
authDomain: "***",
projectId: "***",
storageBucket: "***",
messagingSenderId: "***",
appId: "***",
};
const app = !firebase.apps.length
? firebase.initializeApp(firebaseConfig)
: firebase.app();
const db = app.firestore();
const auth = app.auth();
const provider = new firebase.auth.GoogleAuthProvider();
export { db, auth, provider };

错误:

Module not found: Package path . is not exported from package <project location>node_modulesfirebase (see exports field in <project location>node_modulesfirebasepackage.json)
Did you mean './firebase'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
> 1 | import * as firebase from "firebase";
2 |
3 | const firebaseConfig = {
4 |   apiKey: "***",
Import trace for requested module:
./pages_app.js
https://nextjs.org/docs/messages/module-not-found

文件:/pages_app.js

import "../styles/globals.css";
import { useAuthState } from "react-firebase-hooks/auth";
import { auth, db } from "../firebase";
import Login from "./login";
function MyApp({ Component, pageProps }) {
const [user] = useAuthState(auth);
if (!user) return <Login />;
return <Component {...pageProps} />;
}
export default MyApp;

您应该将您的firebase导入更改为:

import * as firebase from "firebase"

您应该将'firebase'替换为'./firebase',如错误消息中所示

我也遇到过同样的问题。你需要做的是打电话给

import * as firebase from "firebase/app"

而不是CCD_ 4。

如果您正在尝试使用诸如GoogleAuthProvider之类的所有函数,你必须按照导入

import { getAuth, GoogleAuthProvider } from "firebase/auth";

我希望这能有所帮助。

相关内容

  • 没有找到相关文章

最新更新