A few hours ago running npm install -g firebase-tools in our CI system started failing. We pinned to v7.7.0 to fix the issue.
Does not work
npm install -g firebase-tools
Works
npm install -g [email protected] works
Docker Engine Version: 18.09.6
Kernel Version: Linux 95319c6db09e 4.15.0-1043-aws #45-Ubuntu SMP Mon Jun 24 14:07:03 UTC 2019 x86_64 Linux
Starting container google/cloud-sdk
image is cached as google/cloud-sdk, but refreshing...
latest: Pulling from google/cloud-sdk
Digest: sha256:1323aeb05506dada2034d94e1bcd3504ca6e76263e68db1fac78d07fd22cc259
Status: Image is up to date for google/cloud-sdk:latest
using image google/cloud-sdk@sha256:1323aeb05506dada2034d94e1bcd3504ca6e76263e68db1fac78d07fd22cc259
Run npm install -g firebase-tools in a google/cloud-sdk container
npm install -g firebase-tools
Tools install
/root/.nvm/versions/node/v12.13.0/bin/firebase -> /root/.nvm/versions/node/v12.13.0/lib/node_modules/firebase-tools/lib/bin/firebase.js
> [email protected] postinstall /root/.nvm/versions/node/v12.13.0/lib/node_modules/firebase-tools/node_modules/protobufjs
> node scripts/postinstall
sh: 1: node: Permission denied
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/firebase-tools/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! [email protected] postinstall: `node scripts/postinstall`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] postinstall script
I have... news. First, I can replicate this. Yaaaayyyy.....
Second, I can put my finger on the fact that we now include @google-cloud/pubsub as a dependency for the emulators, which includes protobufjs. protobufjs was previously only a dev dependency, so it never would have run it's postinstall script in the container like this.
When running postinstall scripts, npm attempts to not run as root (for reasons). When running as root, npm will try to prevent the user from doing things that could have bad consequences. There is a parameter named unsafe-perm that can disable this.
Either run the npm install -g in the container as root with the --unsafe-perm flag (preferred, generally), or do npm config set unsafe-perm true somewhere before (which turns off this behavior everywhere, which wouldn't be desirable outside of a container, probably).
I hope that answers your question!
Thanks that worked npm install --unsafe-perm -g firebase-tools
in my case this worked for me
npm install --unsafe-perm -g firebase-tools
then followed by
npm install --unsafe-perm -g firebase
and lastly
npm i firebase
bkendall, you rock! Your solution worked for me at once. Thanks for providing the explanation as well!
Most helpful comment
I have... news. First, I can replicate this. Yaaaayyyy.....
Second, I can put my finger on the fact that we now include
@google-cloud/pubsubas a dependency for the emulators, which includesprotobufjs.protobufjswas previously only a dev dependency, so it never would have run it's postinstall script in the container like this.When running postinstall scripts,
npmattempts to not run asroot(for reasons). When running as root,npmwill try to prevent the user from doing things that could have bad consequences. There is a parameter named unsafe-perm that can disable this.Either run the
npm install -gin the container asrootwith the--unsafe-permflag (preferred, generally), or donpm config set unsafe-perm truesomewhere before (which turns off this behavior everywhere, which wouldn't be desirable outside of a container, probably).I hope that answers your question!