-
Notifications
You must be signed in to change notification settings - Fork 391
TypeError: Cannot read property 'INTERNAL' of undefined at FirebaseNamespace.initializeApp #593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I found a few problems with this issue:
|
resolved through the steps described in this spectrum thread: |
Came across the same error while using it together with TypeScript: import * as admin from 'firebase-admin'; The key to solve the issue was to set the import admin from 'firebase-admin'; |
@ofhouse that sounds like some other problem. We have the following TypeScript integration test which uses the Can you provide a minimal repro of the problem? |
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() |
Why was this closed? This is still an issue in 9.11.1. |
The workaround @Samuel-Beslogic provided prevents the error but it's not really a solution. I don't want to import the whole package when I only need firestore for example. Cloud functions cold start time is already bad enough, small imports are essential here. Also I don't have any idea how this even happened. I am on the exact same version of firebase-admin, firebase-functions and firebase-tools that I've been using the past few weeks and didn't change my code in any way but as of today I run into this issue with all functions I (re)deploy. Could this be caused by the environment (firebase cloud functions)? Versions tested: firebase-tools: 9.16.5, 9.16.6, 9.18.0 This works:
This doesn't:
Error message:
|
It's typescript. 4.3.5 works, 4.4.2 doesn't. Hope that helps @hiranya911 |
We don't support destructured imports in the Admin SDK. That's why you won't find that style of imports in any of our existing examples (see https://firebase.google.com/docs/admin/setup#add-sdk). If it had worked in the past then you've been lucky.
You won't get any import size benefits by importing the SDK this way -- at least not with our current implementation. Functions like To get any meaningful import size benefits first we need to expose proper ES6 module entry points (see #1230). Then on top of that we will need to further refactor our implementation, and split the monolithic implementations of import { initializeApp } from 'firebase-admin/app'; But in the meantime the Admin SDK only (officially) supports the following imports: // CJS
const admin = require('firebase-admin');
// TypeScript
import * as admin from 'firebase-admin'; For any other import style you may want to try YMMV. |
@hiranya911 Informative, thanks. I think you mainly need to |
I can confirm this. Tried on several projects with the latest typescript and it works. |
Just in case anyone else comes across this issue, make sure you import looks this
not this
If it is like ^ Typescript won't throw an error but firebase will throw an error at runtime. |
@josh18 It seems that firestore isn't part of I'm using
|
@chaosLegacy to get firestore I use this
after initializing the app. See if that works for you. |
@chaosLegacy , import from 'firebase-admin/app' instead of 'firebase-admin'. |
I face this issue on my local environment. But everything is working well on a docker environment with the same project (I completely deleted cache and images to prevent any conflict with previous versions). Both environments share the same version for How can this be different between those two environments? Any idea? |
For me the problem seemed to be in the package-lock.json. After deleting it (and also the node_modules folder) and running |
This issue still exists using adminsdk 11.10.1
this still works though |
do import { initializeApp } from 'firebase-admin/app'; don't import { initializeApp } from 'firebase-admin'; tsconfig.json {
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
// .
// .
// .
// Other options
} |
Is there an explanation for this fix? |
Wow, this makes no sense... |
Uh oh!
There was an error while loading. Please reload this page.
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
Clone the following repository:
https://github.com/liamdanielduffy/firebase-admin-bug-repro
Run
npm install
oryarn
in the repository root.Run
npm run dev
oryarn dev
to start the server.Visit
localhost:3000/api/graphql
.See the following message printed in the server logs:
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 inlibraries/apollo/getContext
is called. This function attempts to pass the firebase app as part of the 'context' for all the graphql resolvers defined inlibraries/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
this
is undefined, creating the error thrown.Why would that happen? Am I initializing this in the wrong way or in the wrong place?
The text was updated successfully, but these errors were encountered: