javascript - 已成功找到“Firebase”包。但是,这个包本身指定了一个无法解析的“主”模块字段
问题描述
我正在尝试在 expo 托管的 react-native 应用程序中读取和写入 firestore,使用 firebase 的身份验证和 firebase 的存储。
完全错误:
While trying to resolve module `firebase` from file `C:\Users\joshu\Desktop\VSProjects\VolleyballConnect\firebase.js`, the package `C:\Users\joshu\Desktop\VSProjects\VolleyballConnect\node_modules\firebase\package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`C:\Users\joshu\Desktop\VSProjects\VolleyballConnect\node_modules\firebase\index`. Indeed, none of these files exist:
* C:\Users\joshu\Desktop\VSProjects\VolleyballConnect\node_modules\firebase\index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
* C:\Users\joshu\Desktop\VSProjects\VolleyballConnect\node_modules\firebase\index\index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
我的 Firebase 配置文件:
import firebase from "firebase";
import { initializeApp } from "firebase/app";
import "firebase/firestore";
import "firebase/auth";
import "firebase/storage";
// I'm using the example key here, I have the correct config
const firebaseConfig = {
apiKey: "api-key",
authDomain: "project-id.firebaseapp.com",
databaseURL: "https://project-id.firebaseio.com",
projectId: "project-id",
storageBucket: "project-id.appspot.com",
messagingSenderId: "sender-id",
appId: "app-id",
measurementId: "G-measurement-id",
};
if (firebase.apps.length === 0) {
initializeApp(firebaseConfig);
}
const db = firebase.firestore();
const auth = firebase.auth();
const storage = firebase.storage();
export { db, auth, storage };
我安装了这个firebase
包:
expo install firebase
任何帮助将不胜感激。谢谢!
解决方案
我今天遇到了同样的问题,就我而言,它已通过以下方式解决。
1.
// v9 compat packages are API compatible with v8 code
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
从 ↓</p>
if (firebase.apps.length === 0) {
initializeApp(firebaseConfig);
}
↓</p>
app = firebase.initializeApp(firebaseConfig)
为了安全起见,我分享了我的 firebase.js(隐藏个人信息)
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
const firebaseConfig = {
apiKey: "AIzxxxxxxxxxxxxxxxxxxxBbBFNGMI",
authDomain: "sixxxxxxxxxcc8.firebaseapp.com",
projectId: "sxxxxxxxxxxx8",
storageBucket: "xxxxxxxxxxxxxcc8.appspot.com",
messagingSenderId: "6xxxxxxxxxx",
appId: "1:65xxxxxxxx13:web:d0exxxxxxxxxxxxxxxxx7c"
};
let app;
if (firebase.apps.length === 0) {
app = firebase.initializeApp(firebaseConfig)
} else {
app = firebase.app();
}
const db = app.firestore();
const auth = firebase.auth();
export { db, auth };
推荐阅读
- lua - 如何调用复制存储中的函数
- html - 调整窗口大小时文本对齐过渡
- graph - 在 CPLEX 中有向图中依赖于集合/子集的弧的初始化
- python - 将程序转换为 Python 可执行文件后,不会创建文件夹
- facebook - 如何从 Facebook 生成 JWT 类型的访问令牌
- flutter - 如何处理 in_app_purchase 抖动自动续订订阅
- charts - 图例中的 Google 图表 HTML
- python - Discord.py 引发了未描述异常的奇怪错误
- client - 点燃客户端故障转移
- entity-framework - EF Core 3.x:重复值