Closed leevi978 closed 4 years ago
Hi, do you perhaps have a full code example of how you are initialising the source plugin and your own Firebase instance? Also, have you tried passing a second param to your initialisation (as described here https://firebase.google.com/docs/web/setup#multiple-projects)?
For the source plugin I use the following confic in gatsby-config.js:
{ resolve: 'gatsby-source-flamelink', options: { firebaseConfig: { projectId: process.env.GATSBY_FLAMELINK_PROJECT_ID, clientEmail: process.env.GATSBY_FLAMELINK_CLIENT_EMAIL, privateKey: process.env.GATSBY_FLAMELINK_PRIVATE_KEY.replace(/\n/g, '\n'), databaseURL: process.env.GATSBY_FLAMELINK_DATABASE_URL, storageBucket: process.env.GATSBY_FLAMELINK_STORAGE_BUCKET, }, dbType: 'cf', environment: 'production', content: true, populate: true, navigation: true, globals: true } },
When I initialize a new firebase app, I do so in a seperate file which I then import to gatsby-node.js
` var admin = require('firebase-admin')
var flamelink = require('flamelink/app'); require('flamelink/content'); require('flamelink/storage'); require('flamelink/settings');
const firebaseApp = admin.initializeApp({' credential: admin.credential.cert("[removed for this comment]"), databaseURL: '[removed for this comment]', storageBucket: '[removed for this comment]' }, 'firebase-helper' )
const storage = admin.storage().bucket()
var firestore = firebaseApp.firestore();
const app = flamelink({ firebaseApp, locale: 'no', dbType: 'cf' })
const enApp = flamelink({ firebaseApp, locale: 'en-US', dbType: 'cf' }) `
Ok, thanks. I'm thinking perhaps we can expose an "app name" property which can be set so that the app can be initialised twice without conflict. We'll see if we can get to this early next week. How urgent is this?
That's great, I appreciate the quick response! To be honest, this is keeping me from my main work, which has a deadline at the end of july. I have some minor tasks to keep me busy for a couple of days, however.
We'll look into it and hopefully have a solution for you or at the very least a workaround.
@leevi978 we've added a potential fix to our upcoming release. Would you please install it to see if it resolves your issue? You can get the fix by running the following command:
npm i gatsby-source-flamelink@next
Changes are in the latest release.
npm i gatsby-source-flamelink
Hello again @caweidmann , sorry for the late response. Could you please provide documentation on how to use the new variable? I noticed you added a new variable called name in the helpers/api file. However, in gatsby-node.js, you don't seem to be using it when initializing.
In other words this is the code:
const app = api.initApp({ firebaseConfig, environment, dbType })
While I wonder if it should be something like this?
const app = api.initApp({ firebaseConfig, environment, dbType }, name)
Hello, I am using gatsby-source-flamelink as a plugin for my Gatsby project. I have a case where I need to initialize a firebase app in order to fetch some files during build-time (within gatsby-node.js). When I try to build, however, I get the following errors as shown below. As far as I understand it, gatsby-source-flamelink has already initialized a firebase app, which is initialized as the default app. I attempted to give my own firebase app a name, but firebase requires that the default app is initialized first and thus throws an error.
I need to be able to either initialize a new firebase app on my own, or be able to access the already initialized firebase app. Both the gatsby-source-flamelink app and my own custom app has the same credentials. My own app is initialized during my own project's gatsby-node.js script.
The errors I get:
` ERROR #11321 PLUGIN
"gatsby-source-flamelink" threw an error while running the sourceNodes lifecycle:
The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.
74 | const startTime = present(); // Initialize Flamelink app 75 |
File: node_modules\gatsby-source-flamelink\gatsby-node.js:76:25
Error: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.
error.js:42 FirebaseAppError.FirebaseError [as constructor] [trondheim-demo]/[firebase-admin]/lib/utils/error.js:42:28
error.js:88 FirebaseAppError.PrefixedFirebaseError [as constructor] [trondheim-demo]/[firebase-admin]/lib/utils/error.js:88:28
error.js:123 new FirebaseAppError [trondheim-demo]/[firebase-admin]/lib/utils/error.js:123:28
firebase-namespace.js:68 FirebaseNamespaceInternals.initializeApp [trondheim-demo]/[firebase-admin]/lib/firebase-namespace.js:68:23
firebase-namespace.js:408 FirebaseNamespace.initializeApp [trondheim-demo]/[firebase-admin]/lib/firebase-namespace.js:408:30
api.js:54 Object.initApp [trondheim-demo]/[gatsby-source-flamelink]/helpers/api.js:54:14
gatsby-node.js:76 Object.
[trondheim-demo]/[gatsby-source-flamelink]/gatsby-node.js:76:25
Generator.next
gatsby-node.js:3 asyncGeneratorStep [trondheim-demo]/[gatsby-source-flamelink]/gatsby-node.js:3:103
gatsby-node.js:5 _next [trondheim-demo]/[gatsby-source-flamelink]/gatsby-node.js:5:194
gatsby-node.js:5 [trondheim-demo]/[gatsby-source-flamelink]/gatsby-node.js:5:364
new Promise
gatsby-node.js:5 Object.
[trondheim-demo]/[gatsby-source-flamelink]/gatsby-node.js:5:97
gatsby-node.js:221 Object.sourceNodes [trondheim-demo]/[gatsby-source-flamelink]/gatsby-node.js:221:19
api-runner-node.js:259 runAPI [trondheim-demo]/[gatsby]/dist/utils/api-runner-node.js:259:37
From previous event:
api-runner-node.js:261 runAPI [trondheim-demo]/[gatsby]/dist/utils/api-runner-node.js:261:22
api-runner-node.js:378 Promise.catch.decorateEvent.pluginName [trondheim-demo]/[gatsby]/dist/utils/api-runner-node.js:378:15
From previous event:
api-runner-node.js:377 [trondheim-demo]/[gatsby]/dist/utils/api-runner-node.js:377:12
timers.js:439 processImmediate internal/timers.js:439:21
From previous event:
api-runner-node.js:371 [trondheim-demo]/[gatsby]/dist/utils/api-runner-node.js:371:11
From previous event:
api-runner-node.js:278 module.exports [trondheim-demo]/[gatsby]/dist/utils/api-runner-node.js:278:12
source-nodes.js:88 _default [trondheim-demo]/[gatsby]/dist/utils/source-nodes.js:88:36
source-nodes.js:29 sourceNodes [trondheim-demo]/[gatsby]/dist/services/source-nodes.js:29:34
index.js:29 bootstrap [trondheim-demo]/[gatsby]/dist/bootstrap/index.js:29:35
develop-process.js:124 async module.exports [trondheim-demo]/[gatsby]/dist/commands/develop-process.js:124:7 `