Skip to content

process.env.FIREBASE_CONFIG is not populated #596

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

Closed
stari4ek opened this issue Dec 16, 2019 · 12 comments
Closed

process.env.FIREBASE_CONFIG is not populated #596

stari4ek opened this issue Dec 16, 2019 · 12 comments

Comments

@stari4ek
Copy link

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Linux 7u 5.3.0-24-generic Updating README firebase-admin-node#26-Ubuntu SMP Thu Nov 14 01:33:18 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • Firebase SDK version: 7.10.0
  • Firebase Product: firebase-functions/firebase-admin
  • Node.js version: nodejs10 runtime
  • NPM version: 6.13.1

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

Relevant Code:

I was trying to adopt https://firebase.google.com/docs/functions/config-env#automatically_populated_environment_variables.
Deploying firebase function (http) with:

if (process.env.FIREBASE_CONFIG === undefined) {
    throw new Error('Missing FIREBASE_CONFIG');
}
...
admin.initializeApp(opts);

makes deployment to fail.

From terminal:

$ firebase deploy --only functions:admin.forceRcUpdate
✔ scheduler: all necessary APIs are enabled
⚠ functions[admin-forceRcUpdate(us-central1)]: Deployment error.
Error setting up the execution environment for your function. Please try deploying again after a few minutes.

In logs:

E 2019-12-16T07:16:02.599384474Z admin-forceRcUpdate Error: function terminated. Recommended action: inspect logs for termination reason. Function cannot be initialized.
admin-forceRcUpdate
A 2019-12-16T07:15:58.840Z admin-forceRcUpdate Could not load the function, shutting down. admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate at Object. (/srv/node_modules/@google-cloud/functions-framework/build/src/index.js:67:33) admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate at Object.getUserFunction (/srv/node_modules/@google-cloud/functions-framework/build/src/invoker.js:57:32) admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate at require (internal/modules/cjs/helpers.js:22:18) admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate at Module.require (internal/modules/cjs/loader.js:637:17) admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate at Function.Module._load (internal/modules/cjs/loader.js:531:3) admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate at tryModuleLoad (internal/modules/cjs/loader.js:539:12) admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate at Module.load (internal/modules/cjs/loader.js:600:32) admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate at Module._compile (internal/modules/cjs/loader.js:701:30) admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate at Object. (/srv/functions/src/index.ts:12:11) admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate Detailed stack trace: Error: Missing FIREBASE_CONFIG admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate Is there a syntax error in your code? admin-forceRcUpdate
A 2019-12-16T07:15:58.837Z admin-forceRcUpdate Provided module can't be loaded. admin-forceRcUpdate

Removing access to process.env.FIREBASE_CONFIG fixes the issue.
Local emulator works well with it

@google-oss-bot
Copy link
Collaborator

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@hiranya911 hiranya911 transferred this issue from firebase/firebase-admin-node Dec 16, 2019
@google-oss-bot
Copy link
Collaborator

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@andieromero
Copy link

Hi, thanks for submitting your issue. What version of Firebase CLI firebase-tools are you using?

@andieromero andieromero added Needs: Author Feedback Issues awaiting author feedback and removed needs-triage labels Dec 17, 2019
@stari4ek
Copy link
Author

$ npm list | grep firebase
├─┬ [email protected]
│ ├─┬ @firebase/[email protected]
│ │ ├─┬ @firebase/[email protected]
│ │ │ └── @firebase/[email protected]
│ │ ├── @firebase/[email protected]
│ │ ├─┬ @firebase/[email protected]
├─┬ [email protected]
├─┬ [email protected]

$ npm -g list | grep firebase
├─┬ [email protected]

Same behavior with [email protected]

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Dec 18, 2019
@andieromero
Copy link

andieromero commented Dec 18, 2019

@stari4ek When you downgrade to Node8 do you face this error? We had related issues with Node10 several months back and that bug seems to have been fixed. Just want to confirm.

@andieromero andieromero added Needs: Author Feedback Issues awaiting author feedback and removed Needs: Attention labels Dec 18, 2019
@stari4ek
Copy link
Author

With most recent firebase-tools (7.11.0).
nodejs8 (creating new function or updating existing nodejs10):

i  functions: updating Node.js 8 function admin-someFunc(us-central1)...
⚠  functions[admin-someFunc(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Code in file lib/src/index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error: Missing FIREBASE_CONFIG
    at useServiceAccountCredentials (/srv/src/index.ts:16:15)
    at Object.<anonymous> (/srv/src/index.ts:23:3)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at getUserFunction (/worker/worker.js:439:24)

code:

import 'source-map-support/register';
import * as admin from 'firebase-admin';

const useServiceAccountCredentials: boolean = (() => {
    if (process.env.FIREBASE_CONFIG === undefined) {
        throw new Error('Missing FIREBASE_CONFIG');
    }
   ...
})();

BTW, with nodejs10 deployment takes much longer till it fails and there is no error message from cli:

i  functions: updating Node.js 10 (Beta) function admin-someFunc(us-central1)...
⚠  functions[admin-someFunc(us-central1)]: Deployment error.
Error setting up the execution environment for your function. Please try deploying again after a few minutes.

starts well in emulator:

$ firebase serve --only functions:admin.someFunc
⚠  Your requested "node" version "10" doesn't match your global version "12"
✔  functions: Emulator started at http://localhost:5000
i  functions: Watching "/home/user/dev/prj/develop/fb/functions" for Cloud Functions...
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to .... Non-emulated services will access production using these credentials. Be careful!
...
✔  functions[admin-someFunc]: http function initialized (http://localhost:5000/prj-dev/us-central1/admin-someFunc).

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Dec 19, 2019
@andieromero
Copy link

andieromero commented Dec 19, 2019

@stari4ek I can't repro your error with the code snippet you provided. Can you run using the debug flag to see the full trace? firebase deploy --only functions:admin.forceRcUpdate --debug

@andieromero andieromero added Needs: Author Feedback Issues awaiting author feedback and removed Needs: Attention labels Dec 19, 2019
@andieromero
Copy link

I can't tell from your code snippet - but are you importing firebase-functions before you try to access FIREBASE_CONFIG?

@stari4ek
Copy link
Author

I do not import firebase-functions in index.ts since I do not use anything from it in index.ts.
All functions are implemented in their own modules and they are exported using technique:

import { someFunc } from './someModule'
if (!process.env.FUNCTION_NAME || process.env.FUNCTION_NAME === 'someFunc') {
    exports.someFunc = someFunc;
}

Adding

import * as functions from 'firebase-functions';

does fix the issue.

But firebase-functions does export a lot of stuff I do not need, and I'd prefer to import/call what is really used (plus any IDE will strip those import automatically as non-referenced)
Is there public module/function to setup env explicitly?

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Dec 20, 2019
@joehan
Copy link
Contributor

joehan commented Dec 20, 2019

@stari4ek To import a module just for its side effects, use this syntax:
import 'firebase-functions';
https://www.typescriptlang.org/docs/handbook/modules.html#import-a-module-for-side-effects-only

@andieromero andieromero added Needs: Author Feedback Issues awaiting author feedback and removed Needs: Attention labels Dec 20, 2019
@stari4ek
Copy link
Author

did check with import 'firebase-functions';
works well.

I'm not sure if this is good practice in ts/js, but, honestly speaking, for me it looks more like implementation-specific stuff leaking outside the module during it's import.

This issue could be closed.
Thank you

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Dec 21, 2019
@amonkonanBYF
Copy link

i have same problem, i use node 10, firebase-function 3.7.0 firebase-admin 8.10.0,
function terminated. Recommended action: inspect logs for termination reason. Function cannot be initialized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants