derhuerst / db-cli

A CLI for Deutsche Bahn.
https://github.com/derhuerst/db-cli#db-cli
ISC License
6 stars 1 forks source link

npm install -g: install hook has no write permissions #1

Open krmax44 opened 5 years ago

krmax44 commented 5 years ago

When installing via sudo npm i -g db-cli, this error shows up:

npm WARN deprecated br2nl@1.0.0: Package no longer supported. Contact support@npmjs.com for more info.
/usr/bin/db-dep -> /usr/lib/node_modules/db-cli/dep.js
/usr/bin/db-journey -> /usr/lib/node_modules/db-cli/journey.js

> hafas-client@3.10.1 install /usr/lib/node_modules/db-cli/node_modules/hafas-client
> node lib/generate-install-id.js >id.json

sh: id.json: Keine Berechtigung [ = no permission]
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hafas-client@3.10.1 install: `node lib/generate-install-id.js >id.json`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the hafas-client@3.10.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-06-17T16_14_47_426Z-debug.log
  8,51s user 1,44s system 17% cpu 55,553 total

It does work with sudo yarn global add db-cli. :thinking:

derhuerst commented 5 years ago

The install script of hafas-client (a transitive dependency of db-cli) generates a unique ID and tries to write it to id.json, which apparently it doesn't have write access to.

Can you install other dependencies globally?

krmax44 commented 5 years ago

Yes, other packages install just fine. :no_mouth:

derhuerst commented 5 years ago

Hm. My assumption is that the install script isn't being run as the same user or with the same privileges as the npm process itself.

To investigate this further, running with npm i -g --ignore-scripts db-cli should work fine (but yield a non-functional installation).

derhuerst commented 5 years ago

ping 😉 What does npm i -g --ignore-scripts db-cli give you?

krmax44 commented 5 years ago

sudo npm i -g --ignore-scripts db-cli outputs:

/usr/bin/db-dep -> /usr/lib/node_modules/db-cli/dep.js
/usr/bin/db-journey -> /usr/lib/node_modules/db-cli/journey.js
+ db-cli@1.1.1
added 164 packages from 71 contributors in 8.435s
derhuerst commented 5 years ago

Does it yield a functional install? It shouldn't. Please run db-dep and type a station name to check.

krmax44 commented 5 years ago

No, as expected it says Failed to load the install-unique ID from /usr/lib/node_modules/db-cli/node_modules/hafas-client/id.json.

derhuerst commented 5 years ago

Okay, this indeed an npm permission issue. I could npm install -g a package with an install script that writes a file. The script ran as my local user.

manuels commented 5 years ago

I ran into the same problem. sudo npm i -g --ignore-scripts db-cli and then writing the output of node /usr/local/lib/node_modules/db-cli/node_modules/hafas-client/lib/generate-install-id.js into /usr/local/lib/node_modules/db-cli/node_modules/hafas-client/id.json worked for me.

krmax44 commented 5 years ago

@manuels seems like a good workaround for now, will try later!

derhuerst commented 5 years ago

FYI: There's also this guide on how to move the global installation path to ~/.npm-global.

derhuerst commented 5 years ago

The changes in public-transport/hafas-client#124 have been merged and published as hafas-client@4.5.2. This problem should be fixed with a fresh install of db-hafas.