0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Firebase App named '[DEFAULT]' already existsというエラーの解決方法

Posted at

nuxt.jsでfirebaseと連携したら表題のエラーが出ました。

##①firebase.jsフォルダを開きます
多分こんな感じファイルになってるかと。

firebase.js
import Vue from "vue"

import { firestorePlugin } from "vuefire"
import firebase from "firebase"
import "firebase/firestore"

Vue.use(firestorePlugin)

  firebase.initializeApp({
    apiKey: "うんたら",
    authDomain: "うんたら.firebaseapp.com",
    databaseURL: "https://うんたら.firebaseio.com",
    projectId: "うんたら",
    storageBucket: "うんたら.appspot.com",
    messagingSenderId: "123456789",
    appId: "1:123456789:web:123456789",
    measurementId: "うんたら",
  })

export const db = firebase.firestore()
export const auth = firebase.auth()

##②データを囲む

上記のfirebase.initializeApp({})をif(!firebase.apps.length){}で囲みます。

以下のようになります。

firebase.js
import Vue from "vue"

import { firestorePlugin } from "vuefire"
import firebase from "firebase"
import "firebase/firestore"

Vue.use(firestorePlugin)

if (!firebase.apps.length) {
  firebase.initializeApp({
    apiKey: "うんたら",
    authDomain: "うんたら.firebaseapp.com",
    databaseURL: "https://うんたら.firebaseio.com",
    projectId: "うんたら",
    storageBucket: "うんたら.appspot.com",
    messagingSenderId: "123456789",
    appId: "1:123456789:web:123456789",
    measurementId: "うんたら",
  })
}

export const db = firebase.firestore()
export const auth = firebase.auth()

これでエラーが解決してるはずです。

##その他
↓参考URL↓
Nuxt + Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app)
https://stackoverflow.com/questions/53887447/nuxt-firebase-firebase-app-named-default-already-exists-app-duplicate-ap

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?