-
Notifications
You must be signed in to change notification settings - Fork 204
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
GCLOUD_PROJECT environment variable missing from the Node 10 runtime #437
Comments
I found a few problems with this issue:
|
Hi @peterpeterparker thanks for opening up the new issue. Can you provide a snippet of your functions code? |
sure @thechenky here you go:
|
Hm, I would expect to see something calling Firestore to set the value (since the error is coming from here: firebase-functions/lib/providers/firestore.js:99:23). Is that in the |
This is almost certainly due to |
@thechenky in my case it's exports.UpdateCountriesValues = functions.firestore
.document(COUNTRIES_COLLECTION + '/{needsValues}')
.onWrite(async (change, context) => {
try {
const id = await getID(change);
return updateValues(id, COUNTRIES_COLLECTION);
}
catch (e) {
return e;
}
});
async function updateValues(id, collection) {
const token = await authRequest();
const values = await makeRequest(valuesRequest(token, id));
const batch = db.batch();
let years = [];
values.forEach((value) => {
years.push(value.year.toString());
const collectionName = collection + "-values";
let record = Values(value);
const valueRef = db
.collection(collectionName)
.doc(id.toString() + "-" + value.year.toString());
batch.set(valueRef, record);
if (collection === COUNTRIES_COLLECTION) {
const countryCapitalRef = db
.collection(COUNTRIES_COLLECTION)
.doc(id.toString());
batch.set(countryCapitalRef, {
en: {
capital: value.report_type_eng,
},
ru: {
capital: value.report_type,
}
}, { merge: true });
}
});
years.forEach((year) => {
const yearRef = db
.collection(YEARS_COLLECTION)
.doc(year.toString());
batch.set(yearRef, { year: year });
});
const objectRef = db
.collection(collection)
.doc(id.toString());
batch.set(objectRef, {
"needsValues": false,
}, { "merge": true });
await batch.commit();
return id;
} I'm deploying using the Firebase CLI |
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. |
Thx @MaximBazarov for the code, you were faster than me 😉 @thechenky thx for having a look at the problem and if you still need the example of code from my side or a tester, for sure let me know |
Quick update: Node 10 runtime is the first runtime to not have the |
Is there a different workaround for those that need to use Node 10 runtime? I am using GitHub Actions to auto deploy my projects changes on push and the GitHub NPM action uses a Node 10 container and so if I drop the |
|
I ended up forking the firebase GitHub action repo and changing the container image to use the node 8 runtime |
i set |
Node 10 runtime (which is currently in beta) no longer automatically sets project related environment variables, so I would expect |
@gregghz your deployments should not fail because environment variables are missing. If you're still experiencing this issue please file a new bug and fill out all the required fields. Error 400 is not enough information to debug what may be happening. |
This worked for me as a workaround:
|
Ah, @wvanderdeijl thanks for that - this should indeed work! Anyone experiencing this issue - please use the workaround provided in #437 (comment) 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! |
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. |
Hi there @marcosflick this is due to another env var missing, |
Apologies for accidental duping! It was only related to this comment: #437 (comment). |
Internal tracking bug: 134416569 |
I was hoping to perform firestore actions in the node REPL node --experimental-repl-await But was seeing this:
I'm running Node v10.19.0, firebase-tools v8.2.0, firebase-functions v3.6.1 |
Hi @laurenzlong I'm experiencing this issue again, running a firestore onCreate listener (nodeJS 10 runtime). Updated my firebase-tools to 8.4.2 but still gettng:
|
Experiencing the problem on Node
Any updates on this ? |
@theochampion i delete all my functions and create again, works for me |
for anybody that gets some strange errors like This is what I did to fix it.
|
I updated to firebase-functions: 3.9.0 and it still doesn't work |
Same here, does not work - I keep getting the VSConsole message:
What does this mean ? I am on
|
How reliable this workaround is? I'm also doing the same but So it makes me wonder whether is it just an internal Firebase variable that may change in the future or is it just a bug in the documentation and the variable should be listed there? |
|
@kushal-iotasol There's a workaround given by @wvanderdeijl in their comment further up in the thread, but this didn't seem "permanent" enough for my liking. Here's what worked for me: delete your functions, and then re-deploy them. For some reason, simply re-deploying Node 10 functions over existing Node 8 functions doesn't appear to set the environment variables correctly, whereas deleting them first seems to do the trick! |
The Node 10 environment does not include |
Nope, even the Although hardcoding the |
@antoniooi using it like this works for me:
|
hello ! I just tried and still not working for me.. |
Hello, I got the same issue.
But when uploading my function I got the issue back even if export the variable while uploading my function. So try setting env vars from yaml file like that :
yaml file : Even a wrong value works for me but you could met some issue.
|
hello ! amazing I'm actually working on a other project so I'll send you a
message soon if you fixed my problem !
Le lun. 15 févr. 2021 à 03:02, p2lvoizin <notifications@github.com> a
écrit :
… Hello,
I got the same issue.
On my local environnement exporting the env var fix the issue.
export GOOGLE_APPLICATION_CREDENTIALS="boo"
But when uploading my function I got the issue back even if export the
variable while uploading my function.
For my case exporting the en var from a yaml file fix the issue.
So try setting env vars from yaml file like that :
gcloud functions deploy FUNCTION_NAME --build-env-vars-file FILE_NAME.yaml
FLAGS...
yaml file :
GCLOUD_PROJECT: boo
Even a wrong value works for me but you could met some issue.
spec :
- nodejs12
- firebase-functions 3.13.1
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#437 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQCNRU3MDDRT4REBW5HRMR3S7B6C7ANCNFSM4HL7YSKQ>
.
|
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.
|
This worked for me |
I'll just add here what worked for me since by the looks of it some can still experience problems when using node 10+ Update your snippet from package.json
With the above approach I didn't need to use |
For anyone seeing this warning in the logs when the cloud function is deployed without using the Firebase CLI, I resolved it by adding a
You would need to replace $projectId with your own project's id. Note: I only tested this on initialization of the Firebase Admin SDK with no arguments.
Thanks to @mbleigh for the clarification!
Related links: https://firebase.google.com/docs/functions/config-env#automatically_populated_environment_variables |
It isn't a solution if you have more environments (dev, staging, production) where each environment has its own id. If we hardcode the project name in the config file it's no different from hardcoding the project id in the source code of the application. |
That's right. This is to resolve the warning itself. A solution for multiple environments that I can think of is to generate the |
not working for me |
Any development here? |
anyone found the right solution to shut up the warnings? |
If you're still getting warnings here, theres a good chance you need to reinstall the firebase-tools cli and update firebase within your project --
|
@thatfiredev I upgraded these tools:
My package.json (inside the "functions" folder): {
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "18"
},
"main": "index.js",
"dependencies": {
"axios": "^1.4.0",
"firebase-admin": "^11.10.1",
"firebase-functions": "^4.4.1"
},
"devDependencies": {
"eslint": "^8.15.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^3.1.0"
},
"private": true
} My package.json (one level above the "functions" folder):
Part of my index.js code:
Then deployed my function:
I still get the Error: process.env.GCLOUD_PROJECT is not set. error in the logs when executing the fuction. Plus: now I also don't see any of my logging output in the cloud logs. Not sure if this is related to this projectId issue... I also tried to add this line before initializing the firebase-admin SDK like so:
But this leads to an error when trying to deploy the function to the cloud:
I also set the projectId like so:
But that also didn't help. I also tried setting it within both .runtimeconfig.json files as suggested by @jlin5 but that also didn't help. The only thing that did help? I deleted the function from Firestore and re-deployed it. Yes, after many hours of researching and testing, that was the solution for me. I can't tell you how frustrating this was...now also my logs work properly. |
I'm having this issue. Been working on it all day. So, it's still an issue in September of 2023. Okay, so, for what it's worth, our app was running these dependency versions when we were getting this error:
I downgraded them to these:
...then I redeployed our function and it worked. As additional context, all of our other |
[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/setHere the stack trace of the error I found in the Firebase console:
When I downgrade back to Node v8, I do not face that error.
Were you able to successfully deploy your functions?
Yes
The text was updated successfully, but these errors were encountered: