我正在使用Next.js应用程序从Firebase集合中提取数据。在连接Firebase数据库时,我遇到以下错误:
Failed to compile. Module not found
这似乎来自于带有firebase凭据的config.js文件。它位于以下位置:根目录〉源代码〉firebase〉config.js
当我运行npm firebase -v
时,我得到安装的版本是8.19.2,但是,package.json声明它是^9.8.0。当我试图更新firebase时,它不会做任何事情。
配置文件如下所示:
import firebase from 'firebase';
import { initializeApp } from 'firebase-admin';
import { getFirestore } from 'firebase/firestore';
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "xxxx",
authDomain: "xxxx",
projectId: "xxxx",
storageBucket: "xxxx",
messagingSenderId: "xxxx",
appId: "xxxx",
measurementId: "xxxx"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
export default db;
package.json文件如下所示:
{
"name": "with-redux-toolkit",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@heroicons/react": "^1.0.6",
"@reduxjs/toolkit": "1.5.0",
"@stripe/react-stripe-js": "^1.11.0",
"@stripe/stripe-js": "^1.44.1",
"@tailwindcss/line-clamp": "^0.2.0",
"axios": "^1.1.3",
"currency": "^4.1.0",
"firebase": "^9.8.0",
"firebase-admin": "^9.12.0",
"micro": "^9.4.1",
"moment": "^2.29.4",
"next": "^13.0.3",
"next-auth": "^4.16.4",
"react": "^18.2.0",
"react-currency-format": "^1.1.0",
"react-dom": "^18.2.0",
"react-redux": "7.2.2",
"react-responsive-carousel": "^3.2.23",
"stripe": "^10.17.0"
},
"license": "MIT",
"devDependencies": {
"autoprefixer": "^10.2.5",
"postcss": "^8.2.15",
"tailwindcss": "^2.1.2"
}
}
有人知道会发生什么吗?
先谢谢你。
1条答案
按热度按时间qjp7pelc1#
您在项目中使用了
"firebase": "^9.8.0"
。请尝试使用firebase 9
的官方文档说明或npm中关于firebase 9
的第二个引用,以及:Firebase 9文档:
Npm第二参考:
您的
config.js
应该如下所示:此命令:
获取npm当前版本:-P
要正确检查您计算机上的
firebase
版本,您需要全局安装它!参考:https://firebase.google.com/docs/cli#install-cli-mac-linux然后您可以检查版本: