错误:没有创建Firebase应用程序“[DEFAULT]”-请调用Firebase App.initializeApp()

164
我有一个连接到两个应用程序的 Firebase 数据库,一个是 iOS 应用程序,另一个是使用 Node.js 编写的 Web 应用程序。Web 应用程序是一个基本算法,用于将数据设置到数据库中。每当我运行算法时,都会遇到以下错误信息:Error: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp().请问有人可以帮忙解决吗?
29个回答

0
使用React JS
我的问题是我把Firebase文件夹放在了主项目文件夹中,而不是/src文件夹中。
一旦我移动了这个文件夹,它就完美地工作了。

1
你的回答可以通过提供更多支持性信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人能够确认你的回答是否正确。你可以在帮助中心找到关于如何撰写好回答的更多信息。 - Community

0
我正在使用Ionic和Angular,我的情况是从getAuth和updateProfile进行导入,路由名称在不同版本中是不同的。

0

在我的情况下,我正在使用

getAuth()
getFirestore()

不需要传递应用程序,而是像这样使用它

const app = initializeApp(config);
const auth = getAuth(app);
const db = getFirestore(app);

0
通过创建一个新的React应用程序并添加代码,成功修复了这个错误。
import firebase from "./firebase";

作为App.js中的第一个导入,以修复错误。
import firebase from "./firebase";
import { getAuth} from "firebase/auth";

function App() {
  const auth = getAuth();

return ( 
    <div className="App">
      <p>HW </p>
    </div>
  );
}
export default App;

firebase.js文件中包含了Firebase的初始化代码,它与App.js文件位于同一个目录下。

0
我的问题在AngularFire 7.0中是app.module.ts中的错误导入。
应该是
import { getDatabase } from '@angular/fire/database';
// imports should be from '@angular/fire/...'
import { initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { getAuth, provideAuth } from '@angular/fire/auth';
import { getDatabase, provideDatabase } from '@angular/fire/database';
// wrong imports from 'firebase/...'
import { getDatabase } from 'firebase/database'; // wrong
import { getAuth } from 'firebase/auth'; // wrong

    AngularFireModule.initializeApp(environment.firebase),
    AngularFireAuthModule,
    AngularFireAuthGuardModule,
    provideFirebaseApp(() => initializeApp(environment.firebase)),
    provideAuth(() => getAuth()),
    provideDatabase(() => getDatabase()),

0
在我的情况下,我没有放置。
apply plugin: 'com.google.gms.google-services'

在应用级别的gradle文件中的声明

-1
在我的情况下,解决方案是替换这个。
const firebaseConfig = {
        apiKey: "",
        authDomain: "",
        databaseURL: "",
        projectId: "",
        storageBucket: "",
        messagingSenderId: "",
        appId: "",
        measurementId: ""
    };
const app = initializeApp(firebaseConfig);

转换为这个......

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.8/firebase-app.js";
firebase.initializeApp({
        apiKey: "",
        authDomain: "",
        databaseURL: "",
        projectId: "",
        storageBucket: "",
        messagingSenderId: "",
        appId: "",
        measurementId: ""
    });

希望它对你有用 :)


它不起作用。 - abhi3700

-1

我认为这个错误是因为你在相应的React平台上使用了类组件,但没有得到正确的配置所致。 所以你需要在componentWillMount()中编写配置。

componetWillMount() {
const config = {
apiKey: “xxxxxxxxxxxxxxxxxxxxxxxx”,
authDomain: “auth-bdcdc.firebaseapp.com 20”,
databaseURL: “https://auth-bdcdc.firebaseio.com 7”,
projectId: “auth-bdcdc”,
storageBucket: “auth-bdcdc.appspot.com 2”,
messagingSenderId: “xxxxxxxxxx”
};

-2

你能否总结一下你链接中的步骤,或者描述一下为什么这个解决方案可以解决问题?目前为止,这既没有提供解决方案,也没有提供任何解决 OP 问题的解释。 - MJ12358

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接