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
587
votes
21 answers

How to set environment variables from within package.json?

How to set some environment variables from within package.json to be used with npm start like commands? Here's what I currently have in my package.json: { ... "scripts": { "help": "tagove help", "start": "tagove start" } ... } I…
dev.meghraj
  • 8,542
  • 5
  • 38
  • 76
428
votes
36 answers

Start script missing error when running npm start

I'm receiving this error when trying to debug my node application using the npm start command. Error: npm ERR! Windows_NT 6.3.9600 npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js"…
Andrew Moll
  • 4,903
  • 2
  • 13
  • 15
174
votes
6 answers

How to run eslint --fix from npm script

I am trying to add lint-fix in my package.json. My basic lint is "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs" I did try "lint-fix": "eslint --fix --ext .js,.vue src test/unit/specs test/e2e/specs" but it is throwing my errors…
Marek Urbanowicz
  • 12,659
  • 16
  • 62
  • 87
91
votes
1 answer

How can I reference package version in npm script?

I want to reference my package version in a npm script so I can show current version in the app. Something like { "name": "bla", "version": "1.0.0", "author": "bla bla", "scripts": { "build": "node VERSION=<>…
Evaldo Bratti
  • 7,078
  • 2
  • 18
  • 19
64
votes
4 answers

npm package.json OS specific script

I would like to create a package.json build script that executes slightly different set of commands when run from Windows, Linux, Mac. The problem is that I cannot find a way to put it in package.json file that will run without problems at every…
gawi
  • 2,843
  • 4
  • 29
  • 44
62
votes
3 answers

How to set env var for .npmrc use

I need a module in my project to download a private npm package. To accomplish this, I am using a .npmrc file to supply a read-only token needed to download the package. To keep the token supplied by npm out of the file, I wish to add it as an…
skwny
  • 2,930
  • 4
  • 25
  • 45
59
votes
31 answers

NPM: ENOENT: no such file or directory, rename

I was using gulp on the project, then i decide to deleted all the dev dependencies to switch to webpack, but every time i try to install using npm is get this error: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3…
Miguel Frias
  • 2,544
  • 8
  • 32
  • 53
54
votes
10 answers

NPM scripts not showing in the explorer sidebar

I have this problem with Visual Studio Code for Windows 10: I can't see the NPM scripts in the explorer sidebar. I deleted all the extensions, uninstalled VS Code, and installed the latest version of VS Code again with no custom options and no…
YellowBlue
  • 651
  • 1
  • 5
  • 5
54
votes
26 answers

npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react-is (over 30000ms)

When I want to create a react app I'm encountering the following error: npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react-is (over 30000ms) npm ERR! A complete log of this run can be found in: npm ERR! …
Zack-gtay
  • 641
  • 1
  • 5
  • 4
52
votes
4 answers

Why is npm running prepare script after npm install, and how can I stop it?

Whenever I run npm install it installs the package alright, but then it automatically runs the prepare script. It's worth mentioning that I've already checked that there is no postinstall script in the package.json.
Alex Zak
  • 1,924
  • 2
  • 18
  • 26
48
votes
12 answers

Pass command line -- argument to child script in Yarn

I have a package.json that looks similar to this: "scripts": { "dev": "cross-env BABEL_ENV=client webpack --config webpack/client.development.js && yarn dev:stub-server | cross-env BABEL_ENV=server babel-node src/server/server.js", …
Luciano M. L.
  • 709
  • 1
  • 5
  • 9
47
votes
5 answers

npm scripts: read .env file

I have a simple requirement: In my npm scripts package.json file I have the line: { "scripts": { "example": "some-lib --argument --domain \"https://tld.com\"" } } Now I want the "domain" to be factored out. First try is to use…
David Vielhuber
  • 3,253
  • 3
  • 29
  • 34
44
votes
4 answers

Pass command line args to npm scripts in package.json

I have the below scripts in my package.json: "scripts": { "vumper": "node node_modules/vumper/index.js", "format": "prettier --single-quote -width=80 --write package.json" }, The 'vumper' package takes in a command line argument (such as…
Tony Scialo
  • 5,457
  • 11
  • 35
  • 52
44
votes
2 answers

What does ** mean in a path?

ive been setting up Grunt for my web app to auto build it and im seeing paths like /path/to/file/**/*.js i understand what one wildcard means, but what does 2 in a row mean?
Kev
  • 705
  • 1
  • 5
  • 10
41
votes
11 answers

How to open browser to localhost through npm scripts

I've been trying to figure out how to write a npm script that will culminate with the application being launched in the user's browser without them having to manually open the browser and go to localhost:1234. Right now my script reads as: "start":…
rockchalkwushock
  • 1,143
  • 2
  • 9
  • 19
1
2 3
71 72