2

I'm trying to use the firebase admin sdk in a local node.js script file (outside of firebase-functions) in order to preform some auth and firestore operations.

But I get this error:

{"severity":"WARNING","message":"Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail"}

Error: Failed to determine project ID: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND

Admin SDK initialization:

const admin = await import('firebase-admin');
const serviceKey = require('path/to/serviceKey.json');
admin.initializeApp({
    credential: admin.credential.cert(serviceKey),
    databaseURL: 'https://{project}.firebaseio.com',
});

All the questions I've found on this error are regarding running firebase-functions locally, but I'm not trying to use firebase-functions, I'm only trying to use admin.auth and admin.firestore locally.

Am I missing something here?

1 Answer 1

0

It works with the codes below based on this documentation:

const admin = require('firebase-admin');
const serviceKey = require('./path/to/serviceKey.json');
admin.initializeApp({
    credential: admin.credential.cert(serviceKey),
    databaseURL: 'https://{project}.firebaseio.com'
});

I also saw this question, creating new Google Cloud project from current Firebase project and upgrading Firebase project plan to Blaze Plan fixed the problem.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the answer John. But that code does exactly the same thing as the code piece I wrote. Also, I'm already on the blaze plan.
can you show the whole code or how we can reproduce your issue?
Is await import and require the same? I'm getting error if I'm using your await import, it seems that it will depend on the functionality of your apps. I'll update my answer once you update your question with reproducible codes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.