The npm community forum has been discontinued.
To discuss usage of npm, visit the GitHub Support Community.
preinstall npm hook doesn't execute when installing a specific package
In the scripts section of the package.json, you can use various script-hooks to run automatically when you ‘npm install’ (
preinstall will run before and
postinstall will afterwards for example).
The problem is that when you run npm install -D my-package, it doesn’t run that hook, which is kind of unfortunate. Is this a bug or by design?
In my case, we have to generate a local .npmrc file on the fly with a fresh token from our cloud npm repo before installing. It’s nice to run this process in the
preinstall script but it won’t run when we’re trying to install a specific package.
This is as designed, and is a known quirk.
For future reference, please make sure that if you post to #bugs, you use the template. It makes it a lot easier for me to suss out what’s going on and why.