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
15
votes
8 answers

Next Build hangs forever

I'm building an app with NextJs and Typescript. I'm trying to run next build (yarn build) on my local machine to check for typescript warnings and build errors before deploying. Next build hangs at 'Creating an optimized production build' and hangs…
Dayvvo
  • 231
  • 1
  • 2
  • 8
15
votes
3 answers

How to avoid install of packages in monorepo using Yarn

I built a monorepo using Lerna and Yarn workspaces. Everything works fine but everytime I install a new dependency on a package (let's call him A) using: yarn add Yarn adds it and then triggers the install script of all the packages…
Erazihel
  • 7,295
  • 6
  • 30
  • 53
15
votes
1 answer

NPM Run Build Always Builds Production and Never Development

On an inherited project I have, I am trying to get the build command to build a version other than Production. I have attempted to change the alias in the script section in package.json to pass in extra variables such as --dev and…
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
15
votes
3 answers

Babel with babel-preset-env seems to ignore browserslist config

I’m testing Babel with browserslist in an npm script. Here is my current package.json, in which Babel is doing what I expect: { "name": "npm-scripts-igloo", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { …
15
votes
3 answers

How can NPM scripts use my current working directory (when in nested subfolder)

It's good that I can run NPM scripts not only from the project root but also from the subfolders. However, with constraint that it can't tell my current working path ($PWD). Let's say there's a command like this: "scripts": { ... "pwd": "echo…
Allen
  • 4,431
  • 2
  • 27
  • 39
14
votes
5 answers

Deno: How to substitute npm scripts (package.json)

Since it is not necessary to have package.json file with deno, how can I as a developer have a similar experience just as we have with npm scripts in package.json?
CeamKrier
  • 629
  • 7
  • 15
14
votes
2 answers

sh: SET: command not found in `npm start`

I'm trying to run a react project . and after I run command : npm start , it gave me an error: sh: SET: command not found npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn npm ERR! materials-trace@0.1.0 start:…
Neko
  • 581
  • 1
  • 9
  • 24
14
votes
1 answer

How to push to github with custom commit message with npm scripts?

In my package.json I have this "scripts": { "start": "gulp serve", "git": "git add . && git commit -m 'some-message' && git push --all" }, In the terminal I run npm run git and the changes are pushed. But how can I change the commit…
relidon
  • 2,142
  • 4
  • 21
  • 37
14
votes
2 answers

How to compile typescript into javascript then into 1 file using npm scripts

My current entire package.json file. "scripts": { "build": "webpack", "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\"", "lite": "lite-server", "postinstall": "typings install", "tsc": "tsc", "tsc:w": "tsc…
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
13
votes
1 answer

Is it possible to suppress NPM's echo of the commands it is running?

I've got a bash script that starts up a server and then runs some functional tests. It's got to happen in one script, so I'm running the server in the background. This all happens via 2 npm commands: start:nolog and test:functional. All good. But…
jcollum
  • 43,623
  • 55
  • 191
  • 321
13
votes
1 answer

babel polyfill being included, but forEach still doesn't work in IE11 on NodeLists

I've got Webpack working with Babel and including the @babel/polyfill, yet IE11 is still throwing a SCRIPT438 error when trying to use .forEach on a NodeList. Here's my package.json { ... "scripts": { "build:js": "webpack --config…
Robert_QSS
  • 213
  • 1
  • 4
  • 9
13
votes
1 answer

Can you set aliases for npm scripts inside package.json?

I have a project written in Typescript When developing Locally: ts-node is installed as a dev-dependency, The commands are to start: "ts-node src/index" to init: "ts-node bin/init" to init db: "ts-node bin/database-init" to migrate db:…
lonewarrior556
  • 3,917
  • 2
  • 26
  • 55
13
votes
4 answers

Distributing NPM Scripts With A Package For Use By Project Installing It

I have moved all my linting configuration and related packages/plugins/presets (for prettier, stylelint, eslint, commitlint) out to an npm package. I then use this package in multiple projects and extend or merge over the config into local…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
13
votes
5 answers

Set node environment variable to dynamic value in npm script

I would like to set an environment variable dynamically in an npm script. I'm using cross-env as I'm developing on Windows and the server is Unix-based. I want to initialize an environment variable with the current date (new Date()) so I can access…
PzYon
  • 2,963
  • 3
  • 16
  • 27
13
votes
1 answer

Passing command line arguments to npm 'pre' script and script with multiple commands

Is there a way to pass command line arguments to an npm 'pre' script or to a script which runs multiple commands? Assuming a simple script mySexyScript.js that just logs out the process.argv : console.log(process.argv); This works With an npm…
Fraser
  • 14,036
  • 22
  • 73
  • 118
1 2
3
71 72