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

Next.js cloud function builds failing on first firebase deploy

Open christopherdbull opened this issue 2 years ago • 36 comments

[REQUIRED] Environment info

firebase-tools: 12.7.0

Platform: macOS

Next: 13.4.19

[REQUIRED] Test case

Added firebase to an existing, simple next app with a couple of api endpoints and the cloud function build fails.

[REQUIRED] Steps to reproduce

Add firebase with firebase hosting init to a next.js application with server side endpoints. run firebase deploy

[REQUIRED] Expected behavior

The functions build finishes

[REQUIRED] Actual behavior

Building a Cloud Function to run this application. This is needed due to:
 • Image Optimization
 • non-static component /api/hubspot/route
 • non-static component /api/getstarted/route
 • non-static component /api/superblocks/route

npm ERR! code 2
npm ERR! path /Users/christopherbull/dev/1z_web/one-zero/.firebase/website-399615/functions/node_modules/sharp
npm ERR! command failed
npm ERR! command /Users/christopherbull/.cache/firebase/runtime/shell -c -- (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
npm ERR! /bin/sh: --: invalid option
npm ERR! Usage:	/bin/sh [GNU long option] [option] ...
npm ERR! 	/bin/sh [GNU long option] [option] script-file ...
npm ERR! GNU long options:
npm ERR! 	--debug
npm ERR! 	--debugger
npm ERR! 	--dump-po-strings
npm ERR! 	--dump-strings
npm ERR! 	--help
npm ERR! 	--init-file
npm ERR! 	--login
npm ERR! 	--noediting
npm ERR! 	--noprofile
npm ERR! 	--norc
npm ERR! 	--posix
npm ERR! 	--protected
npm ERR! 	--rcfile
npm ERR! 	--restricted
npm ERR! 	--verbose
npm ERR! 	--version
npm ERR! 	--wordexp
npm ERR! Shell options:
npm ERR! 	-irsD or -c command or -O shopt_option		(invocation only)
npm ERR! 	-abefhkmnptuvxBCHP or -o option

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/christopherbull/.npm/_logs/2023-10-13T11_12_35_546Z-debug-0.log
[2023-10-13T11:12:45.468Z] Error: Command failed: npm i --omit dev --no-audit
    at checkExecSyncError (node:child_process:828:11)
    at Object.execSync (node:child_process:899:15)
    at execSync (pkg/prelude/bootstrap.js:2111:30)
    at prepareFrameworks (/Users/christopherbull/.cache/firebase/tools/lib/node_modules/firebase-tools/lib/frameworks/index.js:367:42)
    at async deploy (/Users/christopherbull/.cache/firebase/tools/lib/node_modules/firebase-tools/lib/deploy/index.js:55:13)

christopherdbull avatar Oct 13 '23 12:10 christopherdbull

I would just like to add that following this guide also leads to the same problem.

cmrqs avatar Oct 18 '23 13:10 cmrqs

I'm on Mac too, Next 13.4.1 and was on firebase tools 12.4.4 until just updated to 12.7.0 to check if it would fix this issue - it did not. Up until yesterday evening my app had been deploying for months nicely to Firebase framework-aware hosting for Next JS. I made today a couple of small code changes - no new libs, no new config, nothing major like that. And suddenly firebase deploy fails in build step with similar symptoms: sharp & libvips.

Checked manually on my Mac to download the sharp-libvips outlined in the error message. Downloaded nicely.

i  functions: updating Node.js 18 (2nd Gen) function firebase-frameworks-trailmapv2-staging:ssrtrailmapv2staging(europe-west1)...
.....
npm ERR! code 1
npm ERR! path /workspace/node_modules/sharp
npm ERR! command failed
npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
npm ERR! sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.14.5/libvips-8.14.5-linux-x64.tar.br
npm ERR! sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
npm ERR! sharp: Installation error: read ECONNRESET

npm ERR! A complete log of this run can be found in: /www-data-home/.npm/_logs/2023-10-22T14_18_41_613Z-debug-0.log.

MaRaSu avatar Oct 22 '23 15:10 MaRaSu

...Tried again to deploy this morning. The issue I reported above 15 hours ago is gone - luckily a temporary Cloud Build issue.

MaRaSu avatar Oct 23 '23 08:10 MaRaSu

Can anyone solve it?

`Building a Cloud Function to run this application. This is needed due to: • non-static component /_not-found

npm ERR! code 2 npm ERR! path /Users//Desktop//.firebase/function-name/functions/node_modules/protobufjs npm ERR! command failed npm ERR! command /Users/**/.cache/firebase/runtime/shell -c -- node scripts/postinstall npm ERR! /bin/sh: --: invalid option npm ERR! Usage: /bin/sh [GNU long option] [option] ... npm ERR! /bin/sh [GNU long option] [option] script-file ... npm ERR! GNU long options: npm ERR! --debug npm ERR! --debugger npm ERR! --dump-po-strings npm ERR! --dump-strings npm ERR! --help npm ERR! --init-file npm ERR! --login npm ERR! --noediting npm ERR! --noprofile npm ERR! --norc npm ERR! --posix npm ERR! --protected npm ERR! --rcfile npm ERR! --restricted npm ERR! --verbose npm ERR! --version npm ERR! --wordexp npm ERR! Shell options: npm ERR! -irsD or -c command or -O shopt_option (invocation only) npm ERR! -abefhkmnptuvxBCHP or -o option

npm ERR! A complete log of this run can be found in: npm ERR! /Users/**/.npm/_logs/2023-10-24T11_44_03_007Z-debug-0.log

Error: An unexpected error has occurred.`

ertugrulaktepe avatar Oct 24 '23 11:10 ertugrulaktepe

I am unable to deploy my production firebase functions due to the same error


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> npm run lint && tsc

/bin/sh: --: invalid option
Usage:  /bin/sh [GNU long option] [option] ...
        /bin/sh [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option

Error: functions predeploy error: Command terminated with non-zero exit code 2
error Command failed with exit code 1.

ginagr avatar Nov 08 '23 21:11 ginagr

Same issue on fresh firebase init and deploy on Mac

miloops avatar Nov 09 '23 07:11 miloops

Please let me know if there are any other logs or info I can send along to help debug - this is a pretty big issue for my company as we cannot deploy updates to our production firebase functions

ginagr avatar Nov 09 '23 17:11 ginagr

Same issue also on MacOS Sonoma

Usage:  /bin/sh [GNU long option] [option] ...
        /bin/sh [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option

Error: functions predeploy error: Command terminated with non-zero exit code 2```

luishugoooo avatar Nov 15 '23 13:11 luishugoooo

Also having the above issue. Clean install, new project, nothing untoward going on. Firebase Functions default code, typescript, [email protected]

IAmKio avatar Nov 16 '23 01:11 IAmKio

I am unable to deploy my production firebase functions due to the same error


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> npm run lint && tsc

/bin/sh: --: invalid option
Usage:  /bin/sh [GNU long option] [option] ...
        /bin/sh [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option

Error: functions predeploy error: Command terminated with non-zero exit code 2
error Command failed with exit code 1.

I was able to deploy by downgrading my firebase tools npm -g install [email protected]

ginagr avatar Nov 16 '23 20:11 ginagr

This just happened to me on an M1 Mac, I removed my current version npm -g uninstall firebase-tools or sudo rm -rf /usr/local/bin/firebase // only if you have installed the CLI in a different way

and reinstalled the old [email protected] did the trick

I am unable to deploy my production firebase functions due to the same error


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> npm run lint && tsc

/bin/sh: --: invalid option
Usage:  /bin/sh [GNU long option] [option] ...
        /bin/sh [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option

Error: functions predeploy error: Command terminated with non-zero exit code 2
error Command failed with exit code 1.

I was able to deploy by downgrading my firebase tools npm -g install [email protected]

german1311 avatar Nov 29 '23 04:11 german1311

I am unable to deploy my production firebase functions due to the same error


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> npm run lint && tsc

/bin/sh: --: invalid option
Usage:  /bin/sh [GNU long option] [option] ...
        /bin/sh [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option

Error: functions predeploy error: Command terminated with non-zero exit code 2
error Command failed with exit code 1.

I was able to deploy by downgrading my firebase tools npm -g install [email protected]

Using [email protected] can provide a workaround if you need to deploy to nodejs20.

samuel-coapps avatar Dec 05 '23 21:12 samuel-coapps

thank

I am unable to deploy my production firebase functions due to the same error


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> npm run lint && tsc

/bin/sh: --: invalid option
Usage:  /bin/sh [GNU long option] [option] ...
        /bin/sh [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option

Error: functions predeploy error: Command terminated with non-zero exit code 2
error Command failed with exit code 1.

I was able to deploy by downgrading my firebase tools npm -g install [email protected]

Using [email protected] can provide a workaround if you need to deploy to nodejs20.

thank you! I just had a WTF moment. I can confirm uninstalling and downgrading to 12.0.0 did the trick.

StephanWalters avatar Dec 09 '23 22:12 StephanWalters

It seems like there's multiple issues here, although the root of the issues may be the use of npm --prefix flag with different npm versions. I wasn't able to reproduce this locally. Here are my versions:

  • next: 14.0.4 (latest)
  • firebase-tools: 13.0.2 (latest)
  • npm: 9.7.2
  • node: v20.4.0
  • macOS: Sonoma 14.2

To help diagnose further, I'd appreciate if others still seeing this problem could provide additional logs and details like the versions listed above.

JulienMartel avatar Dec 21 '23 17:12 JulienMartel

@JulienMartel I still have the same issue.

My env:

  • next: 14.0.4
  • firebase-tools: 13.0.1
  • npm: 10.2.3
  • node: v20.10.0
  • macOS: Sonoma 14.2 (M1)

rzfang avatar Dec 27 '23 10:12 rzfang

I used [email protected] by installed shell command. Just tried @13.0.2 installed by npm under my project directly, and deploy successfully.

@JulienMartel I still have the same issue.

My env:

  • next: 14.0.4
  • firebase-tools: 13.0.1
  • npm: 10.2.3
  • node: v20.10.0
  • macOS: Sonoma 14.2 (M1)

rzfang avatar Dec 28 '23 01:12 rzfang

Same issue here for a pure JS function that's been deployed before without any issues. Env:

  • Apple M1 Pro, Sonoma 14.2.1
  • npm 10.2.3, Node.js 20.10.0
  • firebase CLI 13.0.2 installed and updated with the automatic script.

zarko-tg avatar Jan 02 '24 15:01 zarko-tg

FYI, my current workaround is removing

"predeploy": [
  "npm --prefix \"$RESOURCE_DIR\" run lint"
],

from firebase.json.

That being done the deployment works, but be aware that you lose the automatic linting on deploy. I suppose it might even be a more permanent workaround to pre-chain the linting in the function's package.json on deploy.

zarko-tg avatar Jan 03 '24 10:01 zarko-tg

Per the comments and error logs this issue doesn't seem related to the frameworks integration but rather to the Firebase Functions

leoortizz avatar Jan 03 '24 20:01 leoortizz

FYI, my current workaround is removing

"predeploy": [
  "npm --prefix \"$RESOURCE_DIR\" run lint"
],

from firebase.json.

That being done the deployment works, but be aware that you lose the automatic linting on deploy. I supposed it might even be a more permanent workaround to pre-chain the linting in the function's package.json on deploy.

Thank you very much!

dumitruPuggle avatar Jan 10 '24 11:01 dumitruPuggle

Same issue here.

I was using node 16. It worked just by switching to node v20.5.1 (npm v10.0.0).

gmotzespina avatar Jan 27 '24 03:01 gmotzespina

This help me fix the issue without workarounds: I reinstalled firebase-cli using npm install -g firebase-tools I believe previous I installed using curl -sL https://firebase.tools | bash

cobrakai-lab avatar Jan 29 '24 03:01 cobrakai-lab

I am unable to deploy my production firebase functions due to the same error


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> npm run lint && tsc

/bin/sh: --: invalid option
Usage:  /bin/sh [GNU long option] [option] ...
        /bin/sh [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option

Error: functions predeploy error: Command terminated with non-zero exit code 2
error Command failed with exit code 1.

I'm having the same problem deploying my functions. I've tried downgrading to the versions mentioned above, reinstalling, removing the lint command line in the firebase.json predeploy, and nothing... I'm trying to do it from macOS Sonoma. When I test using emulators, it works normally.

estevan-ulian avatar Jan 30 '24 23:01 estevan-ulian

I am unable to deploy my production firebase functions due to the same error


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> npm run lint && tsc

/bin/sh: --: invalid option
Usage:  /bin/sh [GNU long option] [option] ...
        /bin/sh [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option

Error: functions predeploy error: Command terminated with non-zero exit code 2
error Command failed with exit code 1.

I'm having the same problem deploying my functions. I've tried downgrading to the versions mentioned above, reinstalling, removing the lint command line in the firebase.json predeploy, and nothing... I'm trying to do it from macOS Sonoma. When I test using emulators, it works normally.

I managed to solve it by simply installing firebase-tools in my project directory, not globally: cd my-project/functions && npm install firebase-tools

estevan-ulian avatar Jan 31 '24 12:01 estevan-ulian

I can confirm that lowering the version of firebase tools helped. sudo rm -rf /usr/local/bin/firebase npm -g install [email protected]

Arthurysh avatar Feb 02 '24 12:02 Arthurysh

i had the same problem. i had installed firebase with curl -sL https://firebase.tools | bash command, and seems that caused the issue. after uninstalling it, and installing firebase via npm, firebase deploy works without any error: curl -sL firebase.tools | uninstall=true bash npm uninstall -g firebase-tools i'm using firebase v13.1.0.

stardvst avatar Feb 04 '24 16:02 stardvst

I managed to solve it by simply installing firebase-tools in my project directory, not globally: cd my-project/functions && npm install firebase-tools

This works for me. Thanks!

alexodus avatar Feb 20 '24 07:02 alexodus

On MacOS Sonoma 14.1.1 I fixed it by removing the version installed with curl -sL https://firebase.tools | bash and installing it via brew brew install firebase-cli

vlad-tura avatar Feb 23 '24 18:02 vlad-tura

new mac, node 20, new install through the bash script, deploy failed for the same reason. Has to use answer from https://github.com/firebase/firebase-tools/issues/6446#issuecomment-1925811867 above and reinstall through npm.

It needs more attention from Firebase team. But at least we have workarounds.

HugoGresse avatar Feb 25 '24 16:02 HugoGresse

Yes, the version of Firebase Tools installed by curl is completely broken. Needs fixing.

maccman avatar Feb 26 '24 18:02 maccman