Tuesday 23 May 2017

`npm install` invoked via npm scripts do not respect local .npmrc configs

I have a node module with another module inside it. the inner module is pointed at a private registry. So the following install steps will install everything:

npm install

# post install steps
cd inner-module
npm install

And this works great, because the inner module has a local .npmrc file that looks like this:

registry = "http://our-private-repo/"

however if I add the post install as a package.json script:

"postinstall": "cd inner-module && npm install"

npm run postinstall runs the correct steps but doesn't respect the local .npmrc configuration within inner-module. It doesn't matter if the cd inner-module && npm install commands happen in a shell script or a node script etc., when called directly it works. When invoked via an npm run x script, the .npmrc config is always ignored. Even adding a step like npm config set registry xyz doesn't work specifically when invoked via an npm script.

Why is npm config behavior inconsistent for scripts invoked via npm run? I can work around this with a single shell script that does npm install and then steps into the inner module and installs it, but it would be nice if I didn't have to teach devs working on the project a special command to install the module when there's perfectly good npm install + postinstall scripts.



via William B

No comments:

Post a Comment