firebase-tools: Next.js cloud function builds failing on first firebase deploy
[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)
About this issue
- Original URL
- State: open
- Created 9 months ago
- Reactions: 9
- Comments: 34 (2 by maintainers)
I was able to deploy by downgrading my firebase tools
npm -g install firebase-tools@12.0.0Can 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.`
Same issue also on MacOS Sonoma
On MacOS Sonoma 14.1.1 I fixed it by removing the version installed with
curl -sL https://firebase.tools | bashand installing it via brewbrew install firebase-clii had the same problem. i had installed firebase with
curl -sL https://firebase.tools | bashcommand, and seems that caused the issue. after uninstalling it, and installing firebase vianpm,firebase deployworks without any error:curl -sL firebase.tools | uninstall=true bashnpm uninstall -g firebase-toolsi’m using firebase v13.1.0.I can confirm that lowering the version of firebase tools helped.
sudo rm -rf /usr/local/bin/firebasenpm -g install firebase-tools@12.0.0FYI, my current workaround is removing
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.
Using firebase-tools@12.1.0 can provide a workaround if you need to deploy to nodejs20.
This just happened to me on an M1 Mac, I removed my current version
npm -g uninstall firebase-toolsorsudo rm -rf /usr/local/bin/firebase// only if you have installed the CLI in a different wayand reinstalled the old firebase-tools@12.0.0 did the trick
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 functionsThis worked for my M1 pro, the problem is in the firebase cli:
SOLUTION:
Uninstall all firebase cli:
curl -sL firebase.tools | uninstall=true bashInstall firebase cli from brew or with npm:
brew install firebase-cli|npm install -g firebase-toolsRun your code, example:
firebase deploy --only functionsYes, the version of Firebase Tools installed by curl is completely broken. Needs fixing.
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.
I managed to solve it by simply installing firebase-tools in my project directory, not globally:
cd my-project/functions && npm install firebase-toolsThis help me fix the issue without workarounds: I reinstalled firebase-cli using
npm install -g firebase-toolsI believe previous I installed usingcurl -sL https://firebase.tools | bashI used firebase-tools@13.0.1 by installed shell command. Just tried @13.0.2 installed by npm under my project directly, and deploy successfully.
Same issue on fresh firebase init and deploy on Mac
I am unable to deploy my production firebase functions due to the same error