Jos*_*Gao 15 javascript node.js firebase react-native expo
我正在尝试读取和写入 firestore、使用 firebase 的身份验证以及在 expo 管理的反应本机应用程序中使用 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)
Run Code Online (Sandbox Code Playgroud)
我的 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 };
Run Code Online (Sandbox Code Playgroud)
我安装了该firebase软件包:
expo install firebase
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。谢谢你!
小智 18
为了减小应用程序的大小,firebase SDK (v9.0.0) 变得模块化。在 v8 上,您不能再像以前一样执行 import 语句。
你有两个选择。
这:
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
Run Code Online (Sandbox Code Playgroud)
应改为:
// v9 compat packages are API compatible with v8 code
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
Run Code Online (Sandbox Code Playgroud)
由此:
import firebase from "firebase/compat/app";
import "firebase/compat/auth";
const auth = firebase.auth();
auth.onAuthStateChanged(user => {
// Check for user status
});
Run Code Online (Sandbox Code Playgroud)
对此:
import { getAuth, onAuthStateChanged } from "firebase/auth";
const auth = getAuth(firebaseApp);
onAuthStateChanged(auth, user => {
// Check for user status
});
Run Code Online (Sandbox Code Playgroud)
你绝对应该检查文档
小智 15
我今天遇到了同样的问题,就我而言,已通过以下方式解决。
\n1.
\n// v9 compat packages are API compatible with v8 code\nimport firebase from \'firebase/compat/app\';\nimport \'firebase/compat/auth\';\nimport \'firebase/compat/firestore\';\nRun Code Online (Sandbox Code Playgroud)\n从 \xe2\x86\x93 更改
\nif (firebase.apps.length === 0) {\n initializeApp(firebaseConfig);\n}\nRun Code Online (Sandbox Code Playgroud)\n到\xe2\x86\x93
\napp = firebase.initializeApp(firebaseConfig)\nRun Code Online (Sandbox Code Playgroud)\n\n为了安全起见,我分享我的 firebase.js (隐藏个人信息)
\nimport firebase from \'firebase/compat/app\';\nimport \'firebase/compat/auth\';\nimport \'firebase/compat/firestore\';\n\nconst firebaseConfig = {\n apiKey: "AIzxxxxxxxxxxxxxxxxxxxBbBFNGMI",\n authDomain: "sixxxxxxxxxcc8.firebaseapp.com",\n projectId: "sxxxxxxxxxxx8",\n storageBucket: "xxxxxxxxxxxxxcc8.appspot.com",\n messagingSenderId: "6xxxxxxxxxx",\n appId: "1:65xxxxxxxx13:web:d0exxxxxxxxxxxxxxxxx7c"\n};\n\nlet app;\n\nif (firebase.apps.length === 0) {\n app = firebase.initializeApp(firebaseConfig)\n} else {\n app = firebase.app();\n}\n\nconst db = app.firestore();\nconst auth = firebase.auth();\n\nexport { db, auth };\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
20578 次 |
| 最近记录: |