firebase-functions: GCLOUD_PROJECT environment variable missing from the Node 10 runtime
[REQUIRED] Version info
node: Node v10
[REQUIRED] Steps to reproduce
I have upgraded my functions from Node v8 to Node v10. Compilation as upload in the cloud are ok but I face an error at runtime, respectively GCLOUD_PROJECT
is not found/set
Here the stack trace of the error I found in the Firebase console:
Error: process.env.GCLOUD_PROJECT is not set.
at DocumentBuilder (/srv/functions/node_modules/firebase-functions/lib/providers/firestore.js:99:23)
at cloudFunctionNewSignature (/srv/functions/node_modules/firebase-functions/lib/cloud-functions.js:102:13)
at cloudFunction (/srv/functions/node_modules/firebase-functions/lib/cloud-functions.js:151:20)
at Promise.resolve.then (/srv/node_modules/@google-cloud/functions-framework/build/src/invoker.js:330:28)
at process._tickCallback (internal/process/next_tick.js:68:7)
When I downgrade back to Node v8, I do not face that error.
Were you able to successfully deploy your functions?
Yes
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 46
- Comments: 68 (19 by maintainers)
Commits related to this issue
- Downgrade to node v8 See https://github.com/firebase/firebase-functions/issues/437 — committed to mecaworks/aggregate-management by salah3x 5 years ago
The issue should be fixed in the latest release if you update to 3.0.1. Will close this out. Thanks all for your patience.
I get this error in 3.3.0.
I have a test setup, where I extracted the project initialization into a separate file. When I run one test, it works, when I run two tests, I get this error.
This worked for me as a workaround:
Ah yes, this confirms it then. Thank you for sharing your code! This is definitely a bug on our side with Node 10. I will make a note of this and try to get a fix out - I’ll need to think on the best way to implement it though, so that might take a bit of time. The absence of this env variable impacts most event source providers, not just Firestore like in your case, so we need to be careful on how we go about fixing this. In the mean time, please use Node 8. I’ll make sure to post any updates to this thread periodically.
Quick update: Node 10 runtime is the first runtime to not have the
GCLOUD_PROJECT
environment variable automatically set. Because the firebase functions SDK relies on this env var for most of its event provider code, we need to figure out the best way to get thisGCLOUD_PROJECT
value set. Meanwhile, please continue using Node 8 until this issue is fixed.Ah, @wvanderdeijl thanks for that - this should indeed work! Anyone experiencing this issue - please use the workaround provided in https://github.com/firebase/firebase-functions/issues/437#issuecomment-497626133 or downgrade to Node 8. We are currently working on a fix on our end and I’ll keep this issue open until that fix is rolled out. Thanks for everyone’s patience!
Node 10 runtime (which is currently in beta) no longer automatically sets project related environment variables, so I would expect
process.env.GCP_PROJECT
to not return anything. As a workaround until we fix this please use Node 8 runtime.For anyone still having this issue, the solution by @wvanderdeijl no longer works, but I was able to figure another one out, based on it.
process.env.GCLOUD_PROJECT = (req, res) => { res.send(JSON.parse(process.env.FIREBASE_FUNCTION).projectId); };
Hey @laurenzlong
TLDR; realized the env vars are only populated by/after
require('firebase-functions')
🤦🏻♂️require('firebase-functions')
is necessary.I’m coming from Google Cloud Functions, where (custom) environment variables are ‘real’ - living in the OS, not injected on runtime. So I didn’t realize the mechanism. Sorry for wasting your time, however a little mention in the docs on how this and the deploy works behind the scenes shouldn’t hurt anyone 🙃. There are so many differences between these similar products with a similar name and no centralized place that would explain it.
Same, I have a cloud function that’s been in use for 6 months, was working fine, suddenly yesterday I was unable to deploy because the environment variable is missing. Quite concerning to see that such a change that can affect all deploys just suddenly crops up in production deploys.
GCLOUD_PROJECT still undefined on google cloud functions.
Node 10 functioning perfectly now 😃
i’ve deployed all my functions with NodeJS 10 today, and I see the same issue, but only in functions triggered by Firestore record creation, like:
Functions triggered by HTTP work fine and return data without issues
stackdriver logs are:
package.json:
I ended up forking the firebase GitHub action repo and changing the container image to use the node 8 runtime
Glad you figured it out! Yes we are working on injecting it in the OS, not just on runtime (https://github.com/firebase/firebase-tools/pull/2186)
Hi, got the same issue. My workaround (extending @pavadeli’s solution https://github.com/firebase/firebase-functions/issues/630#issuecomment-600259931 in https://github.com/firebase/firebase-functions/issues/630):
process.env
before:process.env
after:versions:
firebase-tools@8.1.1
&firebase-tools@8.2.0
firebase-functions@3.6.1
node@10.16.2
@laurenzlong
10
8.1.1
&8.2.0
I have tried deploys without region, with
us-central1
&europe-west1
, from two different localhosts and from a docker image in Cloud Build, with no difference in result.Hi everybody!
We’ve attempted all the solutions proposed in this thread and it hasn’t resolved this issue.
Code:
Error:
Could you please propose a fix for all this?
Thank you in advance.