Questions tagged [npm-scripts]

The "scripts" property of the package.json file supported by npm.

The "scripts" property of the file is a dictionary containing script commands that are run at various times in the lifecycle of your package. The key is the lifecycle event, and the value is the command to run at that point.

supports the "scripts" property of the package.json file, for the following scripts:

  • prepublish: Run BEFORE the package is packed and published, as well as on local npm install without any arguments. (See below)
  • prepare: Run both BEFORE the package is packed and published, and on local npm install without any arguments (See below). This is run AFTER prepublish, but BEFORE prepublishOnly.
  • prepublishOnly: Run BEFORE the package is prepared and packed, ONLY on npm publish. (See below.)
  • prepack: run BEFORE a tarball is packed (on npm pack, npm publish, and when installing git dependencies)
  • postpack: Run AFTER the tarball has been generated and moved to its final destination.
  • publish, postpublish: Run AFTER the package is published.
  • preinstall: Run BEFORE the package is installed
  • install, postinstall: Run AFTER the package is installed.
  • preuninstall, uninstall: Run BEFORE the package is uninstalled.
  • postuninstall: Run AFTER the package is uninstalled.
  • preversion: Run BEFORE bumping the package version.
  • version: Run AFTER bumping the package version, but BEFORE commit.
  • postversion: Run AFTER bumping the package version, and AFTER commit.
  • pretest, test, posttest: Run by the npm test command.
  • prestop, stop, poststop: Run by the npm stop command.
  • prestart, start, poststart: Run by the npm start command.
  • prerestart, restart, postrestart: Run by the npm restart command. Note: npm restart will run the stop and start scripts if no restart script is provided.
  • preshrinkwrap, shrinkwrap, postshrinkwrap: Run by the npm shrinkwrap command.

Additionally, arbitrary scripts can be executed by running npm run-script <stage>. Pre and post commands with matching names will be run for those as well (e.g. premyscript, myscript, postmyscript). Scripts from dependencies can be run with npm explore <pkg> -- npm run <stage>.

To find more information :

1068 questions
33
votes
3 answers

How does npm behave differently with ignore-scripts set to true?

I just watched a talk where the speaker recommended running: npm config set ignore-scripts true so that post-install scripts and pre-install scripts of a package don't run. That way, you would avoid a virus in a malicious package. My question is:…
Dan
  • 641
  • 1
  • 7
  • 17
31
votes
2 answers

NPM run parallel task, but wait until resource is available to run second task

In npm, how can I run two or more parallel tasks, but waiting for the resource that the first task will create to be available to the second task to use it, and so forth? example (conceptual): npm run task1 & waitfor task1 then task2 & waitFor task3…
user3303864
30
votes
7 answers

Why do I obtain this error when deploying app to Heroku?

I am getting some kind of error when deploying my app to heroku using git hub. The problem is, I don't understand the heroku logs and the entailing errors. Here is the heroku log: Marcuss-MacBook-Pro:Weather-App marcushurney$ heroku…
Mjuice
  • 1,288
  • 2
  • 13
  • 32
29
votes
5 answers

npm-force-resolutions not working when installing a new package

I'm using the scripts section of the package.json to force resolutions: "preinstall": "npx npm-force-resolutions" in the resolutions section, I have entered graceful-fs with a specified version: "resolutions": { "graceful-fs": "^4.2.4", }, When…
NthDegree
  • 1,301
  • 2
  • 15
  • 29
28
votes
2 answers

NPM run * doesn't do anything

I was running an Electron project, and everything worked just fine. But now when I run any of the scripts in my package.json (including npm start), it just escapes a line and doesn't do anything. My package.json: { "name": "interclip-desktop", …
Filip Troníček
  • 434
  • 1
  • 5
  • 14
27
votes
2 answers

What's the difference between npm run dev and npm run start in Next.js?

I am wondering what would the difference be between npm run dev and npm run start. To my surprise, I could not find much information online about this topic. Specifically, I'd like to know in the context of React and Next JS. I noticed that with…
Pat Racco
  • 421
  • 1
  • 4
  • 9
26
votes
6 answers

Npm install from repo not running `prepare`

I have an npm package for common components hosted on an internal git server. For some reason when I call npm install in another project I want to consume this in it will not run the prepare hook. Obviously, this does not work since the npm package…
Midevilworm
  • 451
  • 5
  • 10
26
votes
1 answer

NPM preinstall script

I am trying to run some policing script before any packages are installed. For Example: { "name": "pre-hook-check", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" &&…
user98239820
  • 1,411
  • 2
  • 16
  • 30
24
votes
2 answers

run batch file in npm script

Is it possible and how to run a batch script in npm command? I have an angular project, in package.json file, under scripts section, I want to define a npm command to run batch script. I know I can run shell script with keyword bash e.g. "start":…
Anna Morning
  • 522
  • 1
  • 5
  • 18
23
votes
1 answer

Recursively copy files cross-platform via npm script

We have within a package.json build script a copy command (no we cant quickly change that). Is there any solution we can make this work multiplatform with the same syntax easily? I looked in several npm copy packages, but they don't transpile from…
fredalex
  • 433
  • 5
  • 15
22
votes
1 answer

How to disable “Debug” from showing in package.json

How to disable the outlined "Debug" tip from showing up in package.json above the scripts section:
Wenfang Du
  • 8,804
  • 9
  • 59
  • 90
22
votes
3 answers

How to run a post-install script after individual execution of "npm install "

I am maintaining the following directory structure: /home/user/Desktop/ |-- app/ | |-- package.json | `-- server.js |-- node/ | |-- bin/ …
dibyendu
  • 515
  • 1
  • 5
  • 16
19
votes
6 answers

Npm: Run postinstall script only when installed as dependency

I developed a npm package ("node_commons") which is included in my other project like this: package.json (other project) "node-commons": "git+ssh://git@stash.custom.domain.net:7999/npm/libs/node_commons.git" The node_commons package is written in…
Kewitschka
  • 1,445
  • 1
  • 21
  • 35
19
votes
10 answers

How do you correctly use parallelshell with npm scripts?

I am trying to use parallelshell with my node project on Windows to run two processes at the same time. Here is the scripts section of my package.json file: "scripts": { "start": "npm run watch:all", "test": "echo \"Error: no test specified\" &&…
dpberry178
  • 558
  • 6
  • 21
18
votes
1 answer

How to run a script before installing any npm module?

I am trying to make a test for npm packages for my project such that every time I try to install a module i.e run npm install a script must be run before that module is installed. The preinstall script only works with npm install and not…
yawningphantom
  • 386
  • 1
  • 3
  • 9
1
2
3
71 72