简体   繁体   English

Firebase:没有创建 Firebase App '[DEFAULT]' - 调用 Firebase App.initializeApp() (app-compat/no-app)

[英]Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app-compat/no-app)

I am using a react js to build a gallery program, using firebase as the backend.我正在使用 react js 构建一个画廊程序,使用 firebase 作为后端。

But I got some error and error in the config.js.但是我在 config.js 中遇到了一些错误和错误。 I already follow some questions here, but nothing works for me.我已经在这里关注了一些问题,但对我没有任何帮助。

So this is my config.js:所以这是我的 config.js:

// import firebase from 'firebase/app';
import firebase from 'firebase/compat/app';
// import { initializeApp } from 'firebase/app';
// import 'firebase/compat/auth';
// import 'firebase/compat/firestore';
import 'firebase/storage';
import 'firebase/firestore';
import 'firebase/compat/storage'


// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
const firebaseConfig = {
  apiKey: "",
  authDomain: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: ""
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
// firebase.initializeApp();

  const projectStorage = firebase.storage();
  const projectFirestore = firebase.firestore();

  export { projectStorage, projectFirestore}

The error I got is: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app-compat/no-app).我得到的错误是: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app-compat/no-app)。

See that I commented on the code, to see some errors, and it still giving me the same result.看到我评论了代码,看到了一些错误,它仍然给我相同的结果。

Note: I am using firebase ^9.16.0" React JS注意:我使用的是 firebase ^9.16.0" React JS

I found the solution for my own problem.我找到了解决我自己问题的方法。

So that If you're using version 9 (in my case firebase 9.16.0) so you also have to add import 'firebase/compat/firestore';因此,如果您使用的是版本 9 (在我的示例中为 firebase 9.16.0) ,那么您还必须添加import 'firebase/compat/firestore'; not import 'firebase/firestore';导入“firebase/firestore”;

This returns me TypeError: firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.firestore is not a function这返回我TypeError: firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.firestore is not a function

And then changed the way to initialize the app from const app = initializeApp(firebaseConfig);然后将初始化应用程序的方式更改为const app = initializeApp(firebaseConfig); to firebase.initializeApp(firebaseConfig);firebase.initializeApp(firebaseConfig);

Now it works fine in my project.现在它在我的项目中运行良好。

My final code is below, and you can see the different between the above one in the question:我的最终代码如下,您可以在问题中看到上述代码之间的不同:

import firebase from 'firebase/compat/app';
import "firebase/database"
import 'firebase/storage';
import 'firebase/compat/firestore';
import 'firebase/compat/storage';


// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
const firebaseConfig = {
  apiKey: "your api",
  authDomain: "your domain",
  projectId: "your project id",
  storageBucket: "your storage",
  messagingSenderId: "your id",
  appId: "your app id"
};

// Initialize Firebase
// const app = initializeApp(firebaseConfig);
firebase.initializeApp(firebaseConfig);

  const projectStorage = firebase.storage();
  const projectFirestore = firebase.firestore();

  export { projectStorage, projectFirestore}

暂无
暂无

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

相关问题 Flutter Web - No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) - Flutter Web - No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) 如何解决 Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) - How to solve Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) FirebaseError: Firebase: 否 Firebase App '[DEFAULT]' 已创建 - 调用 Firebase App.initializeApp() {颤动网络} - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). {Flutter web} Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) in vue.js - Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) in vue.js Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' 已创建 - 调用 Firebase App.initializeApp() (app/no-app) - Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) React-Native:Firebase 错误:No Firebase App [DEFAULT] 已创建 - 调用 Firebase App.initializeApp()(app/no-app) - React-Native: Firebase Error: No Firebase App [DEFAULT] has been created - call Firebase App.initializeApp() (app/no-app) 没有 Firebase 应用程序“[DEFAULT]”已创建 - 调用 Firebase App.initializeApp() - Firebase 存储 - No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() - Firebase Storage 错误:没有 Firebase 应用程序“[DEFAULT]”已创建 - 调用 Firebase App.initializeApp() - Error: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() Firebase 构建消费者异常<usermanager> // [core/no-app] 没有创建 Firebase App '[DEFAULT]' - 调用 Firebase.initializeApp()</usermanager> - Firebase Exception building a Consumer<UserManager> // [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() 没有创建 Firebase App - 调用 Firebase.initializeApp() - No Firebase App has been created - call Firebase.initializeApp()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM