简体   繁体   English

服务器错误类型错误:firebaseApp.firestore 不是 function 错误

[英]Server Error TypeError: firebaseApp.firestore is not a function error

Here is my code:这是我的代码:

import * as firebase from "firebase/app";
<script src="https://www.gstatic.com/firebasejs/8.7.0/firebase-app.js"></script>
//import "firebase/firestore";
//import {firebase} from 'firebase/app';
import 'firebase/firestore';


const firebaseConfig = {

apiKey: "A*******************",

authDomain: "u*****.com",

projectId: "u******a",

storageBucket: "unl***********.com",

messagingSenderId: "5***********",

appId: "1:5************",

measurementId: "G-"

};

// Initialize Firebase


const firebaseApp =firebase.initializeApp(firebaseConfig);

const db = firebaseApp.firestore();

export { db };

Troubleshooting done so far:目前已解决的问题:

1.Tried importing "import * as firebase from "firebase/app" and import 'firebase/firestore'; 1.尝试从“firebase/app”导入“import * as firebase”并导入“firebase/firestore”;

  1. re-installed npm.重新安装 npm。

  2. deleted nodes and package-lock.json and reinstalled them.删除节点和 package-lock.json 并重新安装它们。

  3. Installed firebase and firestore.安装了 firebase 和 firestore。

错误图片

You are using Firebase SDK version 9 , the way you import and initialize your Firebase SDK is for older version that's why you are receiving that error.您正在使用Firebase SDK 版本 9 ,导入和初始化 Firebase SDK 的方式适用于旧版本,这就是您收到该错误的原因。

Use Firebase version 8 or below to still run your current code without any changes.使用Firebase 版本 8 或更低版本仍然可以运行您当前的代码而无需任何更改。 You can change it in package.json or by running the command below:您可以在package.json或运行以下命令来更改它:

npm install firebase@8.0.0 --save

the sample dependencies in package.json : package.json中的示例依赖项:

"dependencies": {
    "firebase": "8.0.0",
    "next": "11.1.2",
    "react": "17.0.2",
    "react-dom": "17.0.2"
}

But if you want to use the latest Firebase version 9.0.0 and above which is implementing modular API and you want to adapt the modular API. Use compat packages, in your case, it should be:但是,如果您想使用最新的Firebase 版本9.0.0及更高版本,它正在实现模块化 API ,并且您想要调整模块化 API。使用compat包,在您的情况下,它应该是:

import * as firebase from "firebase/compat/app";
import 'firebase/compat/firestore';

Please NOTE :注意

the compat libraries are a temporary solution that will be removed completely in a future major SDK version ( such as version 10 or version 11 ). compat库是一个临时解决方案,将在未来的主要 SDK 版本(例如版本 10 或版本 11 )中完全删除。 Your ultimate goal is to remove compat code and keep only version 9 modular-style code in your app.您的最终目标是删除兼容代码并在您的应用程序中仅保留第 9 版模块化样式代码。

Like Dharmaraj's answer , you should upgrade from version 8 to the modular Web SDK.就像Dharmaraj 的回答一样,您应该从版本 8 升级到模块化 Web SDK。

However I'd recommend upgrading to Modular SDK syntax because has supports tree-shaking and will be lighter than existing version.但是我建议升级到 Modular SDK 语法,因为它支持 tree-shaking 并且比现有版本更轻。 Checkout this Firecast to learn more about new syntax for Firestore: Getting started with Cloud Firestore for Web查看此 Firecast 以了解有关 Firestore 新语法的更多信息: Getting started with Cloud Firestore for Web

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FirebaseApp.DefaultInstance.SetEditorDatabaseUrl 错误 - FirebaseApp.DefaultInstance.SetEditorDatabaseUrl Error 错误:属性 auth 在 FirebaseApp 类型上不存在 - Error: Property auth does not exist on type FirebaseApp .map 不是带有 firestore 的 nextjs 上的 function 错误 - .map is not a function error on nextjs with firestore Ionic Capacitor firebase 推送通知,报错:Default FirebaseApp is not initialized in this process - Ionic Capacitor firebase push notification, error:Default FirebaseApp is not initialized in this process 类型错误:admin.firestore.collection 不是函数 - TypeError: admin.firestore.collection is not a function 错误:无法加载默认凭据(Firebase function 到 firestore) - Error: Could not load the default credentials (Firebase function to firestore) 类型错误:snap.data 不是 function - Firestore 数据库 - TypeError: snap.data is not a function - Firestore Database (Firebase Firestore)TypeError: n.indexOf 不是 function - (Firebase Firestore)TypeError: n.indexOf is not a function Firebase Function、Firestore 和 Axios - 错误:参数“数据”的值不是有效的 Firestore 文档 - Firebase Function, Firestore, & Axios - Error: Value for argument "data" is not a valid Firestore document React 中的 Firestore 错误:未捕获(承诺)TypeError:无法读取 null 的属性(读取“uid”) - Firestore error within React: Uncaught (in promise) TypeError: Cannot read properties of null (reading 'uid')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM