Skip to content
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

Next.js cloud function builds failing on first firebase deploy #6446

Open
christopherdbull opened this issue Oct 13, 2023 · 37 comments
Open

Comments

@christopherdbull
Copy link

christopherdbull commented Oct 13, 2023

[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)
@cmrqs
Copy link

cmrqs commented Oct 18, 2023

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

@MaRaSu
Copy link

MaRaSu commented Oct 22, 2023

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
Copy link

MaRaSu commented Oct 23, 2023

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

@ertugrulaktepe
Copy link

ertugrulaktepe commented Oct 24, 2023

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.`

@ginagr
Copy link

ginagr commented Nov 8, 2023

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.

@miloops
Copy link

miloops commented Nov 9, 2023

Same issue on fresh firebase init and deploy on Mac

@ginagr
Copy link

ginagr commented Nov 9, 2023

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

@FantixX
Copy link

FantixX commented Nov 15, 2023

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```

@IAmKio
Copy link

IAmKio commented Nov 16, 2023

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

@ginagr
Copy link

ginagr commented Nov 16, 2023

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
Copy link

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]

@samuel-coapps
Copy link

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.

@StephanWalters
Copy link

StephanWalters commented Dec 9, 2023

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.

@JulienMartel
Copy link
Contributor

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.

@rzfang
Copy link

rzfang commented Dec 27, 2023

@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
Copy link

rzfang commented Dec 28, 2023

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)

@zarko-tg
Copy link

zarko-tg commented Jan 2, 2024

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
Copy link

zarko-tg commented Jan 3, 2024

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.

@leoortizz
Copy link
Member

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

@dumitruPuggle
Copy link

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!

@gmotzespina
Copy link

Same issue here.

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

@cobrakai-lab
Copy link

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

@estevan-ulian
Copy link

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
Copy link

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

@Arthurysh
Copy link

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

@stardvst
Copy link

stardvst commented Feb 4, 2024

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.

@alexodus
Copy link

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!

@vlad-tura
Copy link

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

@HugoGresse
Copy link

HugoGresse commented Feb 25, 2024

new mac, node 20, new install through the bash script, deploy failed for the same reason.
Has to use answer from #6446 (comment) above and reinstall through npm.

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

@maccman
Copy link

maccman commented Feb 26, 2024

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

@Budyn
Copy link

Budyn commented Mar 1, 2024

Problem still exists. Please!

@epiphanizer
Copy link

Can confirm using the bash script caused issues for me. Just delete the globally installed package found with which firebase, and run which again, you'll see it pointing to the right place if you installed with npm.

@soymartinez
Copy link

This worked for my M1 pro, the problem is in the firebase cli:

Caution

DO NOT INSTALL: curl -sL https://firebase.tools | bash.

SOLUTION:

  1. Uninstall all firebase cli:
    curl -sL firebase.tools | uninstall=true bash

  2. Install firebase cli from brew or with npm:
    brew install firebase-cli | npm install -g firebase-tools

  3. Run your code, example:
    firebase deploy --only functions

@patgmiller
Copy link

Honestly I don't find having a global install the best approach. Especially since I have multiple projects and one would need to be able to manage the different required versions I simply just include firebase as a dependency and everything is solved with npx firebase deploy --only functions

@phillbooth
Copy link

phillbooth commented May 13, 2024

Solution firebase.json changes

"hosting": { "public": ".next", "rewrites": [ { "source": "**", "function": "nextServer" }

Hello everyone, My app is next.js v14, firebase, auth and firestore

For me using the latest version of firebase-tools and "#firebase deploy --only" functions were working but when I did a full deploy I got this error.

I have done a "firebase deploy" test and got an error


Building a Cloud Function to run this application. This is needed due to:
 • non-static route /jobs/[name]/[county]/[id]
 • non-static route /search/results
 • non-static route /sitemap/[person]

I took a look at my firebase.json in the root folder of my app and found it needed some changes.

Here is my full firebase.json file, please take a look at the "Hosting" section for the solution

{ "firestore": { "rules": "firestore.rules", "indexes": "firestore.indexes.json" }, "functions": [ { "source": "functions", "codebase": "default", "ignore": [ "node_modules", ".git", "firebase-debug.log", "firebase-debug.*.log", "*.local" ], "predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint", "npm --prefix \"$RESOURCE_DIR\" run build" ] } ], "hosting": { "public": ".next", "rewrites": [ { "source": "**", "function": "nextServer" } "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ], ], "frameworksBackend": { "region": "europe-west1" } }, "storage": { "rules": "storage.rules" }, "extensions": {} }

@rahulbansal16
Copy link

rahulbansal16 commented Oct 23, 2024

Some of you can resolve this error by making sure that you are not running only firebase deploy --only hosting. Instead, just run firebase deploy.

Delete the .next folder before running the above command.
Make sure that you close all the IDs or terminals that are trying to access the directory.

@raw1359
Copy link

raw1359 commented Nov 21, 2024

[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)

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