[英]Module not found: Can't resolve 'firebase' in
之后:npm 我 firebase
我正在从 firebase 本身而不是从文件导入 firebase
从“firebase”导入 firebase; >在firebase.js文件中<
终端错误 >> ./src/firebase.js 未找到模块:无法在“C:\Users\Home\Documents\dsn\e\Documents.........”中解析“firebase”
npm i firebase
现在安装 v9 Modular 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
您可以在文档中阅读更多相关信息
如果您在模块导入路径前添加“compat”前缀,则没有理由降级到第 8 版,因为第 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 导入。
最近的版本firebase有很多改动,用这个->
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
const firebaseConfig = {
....
};
// Use this to initialize the firebase App
const firebaseApp =firebase.initializeApp(firebaseConfig);
// Use these for db & auth
const db = firebaseApp.firestore();
const auth = firebase.auth();
export { auth, db };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.