找不到模块:软件包路径,未从软件包导出/ Firebase不会在next.js应用程序中更新

2eafrhcq  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(123)

我正在使用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"
  }
}

有人知道会发生什么吗?
先谢谢你。

qjp7pelc

qjp7pelc1#

您在项目中使用了"firebase": "^9.8.0"。请尝试使用firebase 9的官方文档说明或npm中关于firebase 9的第二个引用,以及:

Firebase 9文档

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";

// TODO: Replace the following with your app's Firebase project configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
  // ...
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);

// Initialize Firebase Authentication and get a reference to the service
const auth = getAuth(app);

Npm第二参考

import { initializeApp } from 'firebase/app';
import { getFirestore, collection, getDocs } from 'firebase/firestore/lite';
// Follow this pattern to import other Firebase services
// import { } from 'firebase/<service>';

// TODO: Replace the following with your app's Firebase project configuration
const firebaseConfig = {
  //...
};

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

您的config.js应该如下所示:

import { initializeApp } from "firebase/app";
import { getFirestore } from 'firebase/firestore/lite';

const firebaseConfig = {
    apiKey: "xxxx",
    authDomain: "xxxx",
    projectId: "xxxx",
    storageBucket: "xxxx",
    messagingSenderId: "xxxx",
    appId: "xxxx",
    measurementId: "xxxx"
  };

const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);

export default db;

此命令:

npm firebase -v

获取npm当前版本:-P

要正确检查您计算机上的firebase版本,您需要全局安装它!参考:https://firebase.google.com/docs/cli#install-cli-mac-linux
然后您可以检查版本:

firebase --version

相关问题