preinstall npm hook doesn't execute when installing a specific package


(Joseph Weidinger) #1

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.

(Kat Marchán) #2

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.