找不到模块:无法解析 'firebase'

Module not found: Can't resolve 'firebase' in

之后:npm i firebase

I'am importing firebase from firebase itself & not from a file

从 'firebase'; >在 firebase.js 文件中导入 firebase<

终端错误>> ./src/firebase.js 找不到模块:无法解析 'C:\Users\Home\Documents\dsn\e\Documents..........'

中的 'firebase'

npm i firebase 现在安装 v9 模块化 SDK,因此您不能使用旧的导入。尝试将您的代码重构为:

import { initializeApp } from 'firebase/app';

const firebaseConfig = {
  //...
};

const app = initializeApp(firebaseConfig);

如果您想使用旧语法,请将您的导入更改为兼容库:

import firebase from "firebase/compat/app"
import "firebase/compat/auth"
import "firebase/compat/firestore"
// other services is needed

您可以在 documentation

中阅读更多相关信息

没有理由降级到版本 8,因为如果您在模块导入路径前加上“compat”前缀,版本 9 提供完全向后兼容的导入。

使用:

import firebase from "firebase/compat/app";
// Other libraries might need to also be prefixed with "compat":
import "firebase/compat/auth";

// Then you can then use the old interface, with version 9:
if (!firebase.apps.length) {
  firebase.initializeApp(clientCredentials);
}

升级说明:https://firebase.google.com/docs/web/modular-upgrade

initializeApp 已移至最新版本firebase/app 包
所以从 firebase/app.

导入