firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Cloud Functions deployment with Node.js 14 runtime fails during CI, works locally

Open emilioschepis opened this issue 3 years ago • 13 comments

[REQUIRED] Environment info

firebase-tools: 9.16.0

Platform: GitHub action runner (both ubuntu-latest and macos-latest)

[REQUIRED] Test case

Deploying a set of Cloud Functions with the Node.js 14 runtime fails with a runtime error on optional chaining ?.. This only happens when running on a GitHub action runner, but it works fine on my local machine (macOS).

I have verified that these versions are installed and used on both systems:

  • TypeScript: 4.3.5
  • Node.js: 14.17.4
  • NPM: 6.14.14
  • Firebase CLI: 9.16.0

I have also tried to run the action locally with act and it fails like on the GitHub instance. No useful logs are printed even with --debug mode except for the trace (which points to the optional chaining as a syntax error).

Here you can see one of my public actions that failed with debug enabled: https://github.com/emilioschepis/geonotes-backend/runs/3261106553

As I said, I have no problem deploying the same code (even just cloned) with the same steps. I have verified this is an issue on all my Firebase projects and is not related to the specific one I am using.

I have tried to look around in the code, and it seems to be related to trigger parsing. I am not too sure about this. The log messages immediately before the failure are:

[2021-08-06T10:04:18.560Z] Analyzing nodejs backend spec

Error: Error occurred while parsing your function triggers.

/home/runner/work/geonotes-backend/geonotes-backend/functions/lib/handlers/createNoteActionHandler.js:11
    return sendOutput({ note_id: note?.id });
                                      ^

SyntaxError: Unexpected token '.'

Thank you for your help!

[REQUIRED] Steps to reproduce

  • Initialize Cloud Functions
  • Set engine to 14 and use TypeScript
  • Use es2020 as the tsconfig target
  • Run firebase deploy on local machine → it deploys with no issues
  • Setup a CI workflow on GitHub actions, passing the FIREBASE_TOKEN env variable
  • Run firebase deploy on runner machine → it fails with a syntax error

[REQUIRED] Expected behavior

The action runs like the local environment and is able to deploy the es2020 functions.

[REQUIRED] Actual behavior

The runner fails to deploy functions.

emilioschepis avatar Aug 13 '21 09:08 emilioschepis

these days, firebase-tools updated and it can use node.js16.

how about trying to version up node.js?

shrek-kurata avatar Sep 07 '21 01:09 shrek-kurata

Based on the error message received, it looks like the version of node binary that is used as part of firebase deploy isn't using version of node that understands optional chaining.

Can you double check the version of node binary? e.g. does something like this work?

$ node
> {}?.foo
undefined

taeold avatar Sep 15 '21 17:09 taeold

Hi @taeold , thanks for your answer.

I initially thought that could be a problem, but running node -v gave me a version of v14.17.4. From what I can see, Node.js supports optional chaining by default since v14.0.0 (source)

However, just to make sure I tried your experiment, and it worked correctly. You can see the test run where optional chaining runs fine outside of firebase deploy:

https://github.com/emilioschepis/neates-backend/blob/test/optional-chaining/.github/workflows/test-optional-chaining.yml https://github.com/emilioschepis/neates-backend/runs/3615304532

Let me know if I can provide any more information.

emilioschepis avatar Sep 15 '21 21:09 emilioschepis

I'm having this issue too on any node version from 14.0.0 up to latest.

bradcroteau avatar Oct 14 '21 00:10 bradcroteau

I am having this issue consistently IF I install firebase tools NOT through npm/yarn, but either using a binary or through the firebase.tools shell script.

alexleonov-tactiq avatar Jan 07 '22 07:01 alexleonov-tactiq

Having the same issue. Looks like there are some differences between binary and npm versions.

pavelvlasov avatar Jan 10 '22 00:01 pavelvlasov

@alexleonov-tactiq Thanks for the clue and additional prompts folks. I'll see if I can reproduce the issue today.

taeold avatar Jan 10 '22 18:01 taeold

Hi @taeold, any news on this issue? Thanks.

emilioschepis avatar Feb 27 '22 10:02 emilioschepis

I have this issue consistently and can't deploy functions at all on my machine.

Strangely, I am the only person on my team with the issue. We are all using the same repo, same node version (v14.17.6, managed by nvm), using yarn and yarn.lock. I have tried uninstalling and reinstalling node modules by removing node_modules, running yarn cache clean, and also yarn rebuild and I have done this with three different node versions. I have globally uninstalled and reinstalled firebase-tools@latest.

alex-image avatar Mar 07 '22 20:03 alex-image

fixed by upgrading node to v16.8.0 and then reinstalling firebase-tools globally:

nvm install v16.8.0
nvm use v16.8.0
npm install -g firebase-tools@latest

binaries installed by running npm install -g seemed to persist in spite of switching node versions with nvm, so maybe this issue is the result of globally-installed binaries that are still executable via command line even when the node version has been updated?

alex-image avatar Mar 07 '22 20:03 alex-image

Same issue.. Cannot deploy with optional chaining..

node -v
v16.14.0

npm -v
8.5.5

"engines": {
    "node": "16"
  }

floriangbh avatar Apr 20 '22 10:04 floriangbh

@taeold Could you take another look at this when you have a chance? It seems like some folks are seeing this on Node 16 now too.

Bryan and I discussed this in the triage meeting a bit, and it seems like the underlying issue is whatever version of node is being used by CI enviorments. We could add some debug logging in the discovery step to narrow this down. Also, the prepackaged Firepit builds are using Node 12, so that may be the reason we're seeing this often - we should update that in the next major version.

joehan avatar Apr 25 '22 20:04 joehan

For those, who still encounter this issue, this is what helped me: I had uninstalled all versions of my firebase-tools using:

  1. npm uninstall -g firebase-tools
  2. which firebase and them rm -f <PATH_TO_FIREBASE>

and then install it again npm i -g firebase-tools

GiddeonWyeth avatar Aug 07 '22 09:08 GiddeonWyeth

Hey @emilioschepis. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Jan 19 '23 02:01 google-oss-bot

Hi @taeold,

I see that the issue has the label "Needs: Author Feedback", could you clarify which kind of feedback you need? I haven't really tried deploying this again, so I don't know if the underlying issue is fixed or if support for Node.js 16+ makes this issue obsolete.

If it does, let me know and I'll close this issue. Thanks.

emilioschepis avatar Jan 22 '23 16:01 emilioschepis

It appears this issue can be resolved by installing the latest firebase CLI via npm i -g firebase-tools. Although I appreciate some folks may want to stick with the binary version.

@emilioschepis - Are you able to confirm if this is still a problem with the latest binary version of firebase-tools?

russellwheatley avatar Nov 10 '23 16:11 russellwheatley

Hey @emilioschepis. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Nov 21 '23 02:11 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@emilioschepis if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Nov 24 '23 02:11 google-oss-bot