Marcus Junius Brutus Marcus Junius Brutus - 1 year ago 68
Node.js Question

running 'npm install' from shell also runs the 'prepublish' script

This is a SSCCE.
Given the following


"name": "foo",
"version": "1.0.0",
"description": "",
"scripts": {
"prepublish": "echo \"pre-publish script called\""
"devDependencies": {
"dependencies": {
"lodash": "^4.10.0"

npm install
from the shell, results in the
script also being executed:

$ npm install

> foo@1.0.0 prepublish /tmp/so
> echo "pre-publish script called"

pre-publish script called
npm WARN foo@1.0.0 No description
npm WARN foo@1.0.0 No repository field.
npm WARN foo@1.0.0 No license field.

If the
script gets renamed to e.g.
it is no longer executed with
npm install
. Problem is, I need the
script as I typically perform static type analysis and Mocha tests prior to publishing to npm.

Is this a bug or a feature and how do I get around it? There should be no need to run my Mocha tests when I simply wish to install the

My environment is:

$ npm --version && node --version

Answer Source

As I said it's not a bug (although everyone wants this functionality to be fixed), but there is a solution. Check out to help with this very situation.

Solution summary

(from the in-publish package page)

 npm install --save in-publish

Then in package.json:

  "scripts": {
    "prepublish": "in-publish && thing-I-dont-want-on-dev-install || not-in-publish"

You can also use not-in-install and in-install instead of in-publish

  "scripts": {
    "prepublish": "not-in-install && thing-I-dont-want-on-dev-install || in-install"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download