Is it any npm option exist to disable postinstall
script while installing package? Or for rewriting any field from package.json
?
-
2The question is very clear but...is by any chance _this_ your end-goal? https://github.com/zloirock/core-js#postinstall-message ;-) – conny Apr 11 '20 at 10:20
6 Answers
It's not possible to disable only postinstall
script. However, you can disable all scripts using:
$ npm install --ignore-scripts
As delbertooo mentioned in the comments, this also disables the scripts of the dependencies.

- 1,478
- 3
- 14
- 32

- 40,904
- 21
- 118
- 94
-
2Thx. This is exactly what I need. Where can I find such options? This is not described in 'npm help install', 'npm help config' and 'npm help scripts'. – farwayer May 06 '14 at 23:55
-
3I checked the code directly: https://github.com/npm/npm/blob/master/lib/build.js#L179 – Gergo Erdosi May 06 '14 at 23:58
-
112Caution! The option `--ignore-scripts` disables ALL scripts - even from your dependencies. If your dependencies need to run scripts to e.g. install some binaries they may break / be incomplete. – delbertooo Nov 12 '15 at 17:53
-
10So is there a technique then to install node_modules (and all their scripts) but ignore only the main package's scripts ? – Derrick Nov 30 '17 at 14:41
-
6Not only this, but `--ignore-scripts`, or the associated config option (which I set globally) will also mean that `npm run start` will silently do nothing and report success. Amaze. – Ash Berlin-Taylor Jan 24 '19 at 12:27
You can also enable the settings in npm configuration file.
npm config set ignore-scripts true
Note: This will disable scripts for all NPM packages.

- 828
- 12
- 13
-
3This should be the answer. See npm blog post: https://blog.npmjs.org/post/141702881055/package-install-scripts-vulnerability – Pieter Venter Feb 22 '20 at 17:05
-
16Note that it also disables the ability to manually execute `npm run …` - it will simply do nothing, without any warning. – CodeManX Jul 30 '20 at 20:13
-
I wanted to disable postinstall script for my project but wanted all scripts of my project's dependencies to run when I do npm install
.
This is what I ended up doing.
- Create a script
./scripts/skip.js
if (process.env.SKIP_BUILD) {
process.exit(0);
} else {
process.exit(1);
}
- In your package.json file
"scripts": {
...
"postinstall": "node ./scripts/skip.js || npm run build",
...
}
now just set the environment variable SKIP_BUILD=1 to prevent your package from building and your dependencies will build just fine
SKIP_BUILD=1 npm install

- 2,170
- 23
- 24
-
3Nice! I'd probably just do "postinstall": "node process.env.RUN_POSTINSTALL && npm run build" though – ihor.eth Dec 14 '20 at 21:23
-
I attempted the solution in the comment based on RUN_POSTINSTALL and I couldn't get it to work. The original answer worked for me. – Reece Daniels Dec 27 '22 at 17:34
To do this for your own library, I recommend something simple like:
#!/usr/bin/env bash
## this is your postinstall.sh script:
set -e;
if [ "$your_pkg_skip_postinstall" == "yes" ]; then
echo "skipping your package's postinstall routine.";
exit 0;
fi
then do your npm install with:
your_pkg_skip_postinstall="yes" npm install

- 90,741
- 139
- 482
- 817
-
2Thanks! This works great if you're just trying to disable your own script but not ALL scripts in all dependencies. – Brian Neisler Nov 30 '18 at 23:07
-
1@BrianNeisler yer very welcome, always feels good to help other people. By the way, I think double brackets [[ ]] might be better than single brackets for most use cases, not sure tho. – Alexander Mills Dec 01 '18 at 01:56
If you're using NPM >= 8, you can also remove the postinstall
script temporarily:
npm pkg set scripts.postinstall="echo no-postinstall"
npm install
Or with NPM 7, like so:
npm set-script postinstall ""
npm install
Source: https://docs.npmjs.com/cli/v7/commands/npm-set-script/