TypeError: Cannot read property 'INTERNAL' of undefined at FirebaseNamespace.initializeApp

See original GitHub issue

[REQUIRED] Step 2: Describe your environment

  • Operating System version: macOS 10.14.4 (18E226)
  • Firebase SDK version: 8.2.0
  • Library version: unclear what this means
  • Firebase Product: initialization of admin app

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

Clone the following repository: https://github.com/liamdanielduffy/firebase-admin-bug-repro

Run npm install or yarn in the repository root. Run npm run dev or yarn dev to start the server. Visit localhost:3000/api/graphql.

See the following message printed in the server logs:

TypeError: Cannot read property 'INTERNAL' of undefined
    at FirebaseNamespace.initializeApp (.../firebase-admin-bug-repro/node_modules/firebase-admin/lib/firebase-namespace.js:392:21)
    ...(rest of stack trace)

Further context

The firebase admin SDK is being initialized in libraries/firebase/initializeAdminApp. The service account key is present in the repository, and is exported from libraries/firebase/getKey.

On each network request to localhost:3000/api/graphql, the function defined in libraries/apollo/getContext is called. This function attempts to pass the firebase app as part of the ‘context’ for all the graphql resolvers defined in libraries/nexus/schema.

I’m not sure why the error is being printed above, but the stack trace above points to this line in the firebase-admin package: firebase-admin/lib/firebase-namespace.js:392

 FirebaseNamespace.prototype.initializeApp = function (options, appName) {
        return this.INTERNAL.initializeApp(options, appName);
    };

this is undefined, creating the error thrown.

Why would that happen? Am I initializing this in the wrong way or in the wrong place?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

79reactions
Samuel-Beslogiccommented, Aug 30, 2021
import { initializeApp} from 'firebase-admin'
initializeApp()

Now gives me this error (used to work). While the following now works

import * as admin from 'firebase-admin'
admin.initializeApp()
45reactions
josh18commented, Oct 31, 2021

Just in case anyone else comes across this issue, make sure you import looks this

import { initializeApp } from 'firebase-admin/app';

not this

import { initializeApp } from 'firebase-admin';

If it is like ^ Typescript won’t throw an error but firebase will throw an error at runtime.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot export firebase-admin's initializeApp function
Why is it not possible to export the initializeApp as a property? For example: index.js const firebaseAdmin = require('firebase-admin'); exports ...
Read more >
Firebase JavaScript SDK Release Notes - Google
When this parameter is set, Cloud Firestore ignores undefined properties inside objects rather than rejecting the API call. Version 7.14.5 - May 21,...
Read more >
cannot read properties of undefined (reading 'apps') firebase
Firebase Modular SDK V9.0.0+ TypeError: Cannot read property 'apps' of undefined ... const app = initializeApp(firebaseConfig) const db = getFirestore(app) ...
Read more >
Cannot read property 'initializeApp' of undefined-Vue.js
Coding example for the question Uncaught TypeError: Cannot read property 'initializeApp' of undefined-Vue.js.
Read more >
Untitled
n */\nexport function deepCopy (value: T): T {\n return deepExtend(undefined, value) as T;\n}\n\n/**\n * Copy properties from source to target (recursively ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found