Skip to main content

Questions tagged [npm-scripts]

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

npm-scripts
Filter by
Sorted by
Tagged with
620 votes
22 answers
1.0m views

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 ...
dev.meghraj's user avatar
  • 8,960
436 votes
34 answers
1.5m views

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" "...
Andrew Moll's user avatar
  • 4,983
208 votes
7 answers
543k views

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/...
Marek Urbanowicz's user avatar
94 votes
2 answers
50k views

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": { "...
Evaldo Bratti's user avatar
72 votes
4 answers
86k views

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 ...
skwny's user avatar
  • 3,080
66 votes
4 answers
36k views

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....
gawi's user avatar
  • 2,922
61 votes
4 answers
66k views

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

Whenever I run npm install <package> 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 ...
Alex Zak's user avatar
  • 2,054
60 votes
31 answers
135k views

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 ...
Miguel Frias's user avatar
  • 2,660
59 votes
11 answers
46k views

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 ...
YellowBlue's user avatar
58 votes
28 answers
115k views

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 ...
Zack-gtay's user avatar
  • 681
55 votes
12 answers
78k views

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 ...
Luciano M. L.'s user avatar
54 votes
6 answers
77k views

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 "...
David Vielhuber's user avatar
50 votes
4 answers
108k views

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' ...
Tony Scialo's user avatar
  • 5,797
47 votes
2 answers
41k views

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's user avatar
  • 735
45 votes
11 answers
141k views

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 ...
rockchalkwushock's user avatar
41 votes
3 answers
45k views

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 ...
Pat Racco's user avatar
  • 561
38 votes
3 answers
37k views

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 ...
Dan's user avatar
  • 711
34 votes
3 answers
18k views

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 ...
user avatar
30 votes
7 answers
50k views

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-...
Mjuice's user avatar
  • 1,288
30 votes
5 answers
62k views

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 ...
NthDegree's user avatar
  • 1,341
29 votes
6 answers
8k views

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. ...
Midevilworm's user avatar
28 votes
2 answers
12k views

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 ...
Filip Troníček's user avatar
28 votes
1 answer
49k views

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": { ...
user98239820's user avatar
  • 1,461
26 votes
1 answer
10k views

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 ...
fredalex's user avatar
  • 473
25 votes
2 answers
14k views

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's user avatar
  • 10.5k
25 votes
2 answers
28k views

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 ...
Anna Morning's user avatar
22 votes
6 answers
8k views

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://[email protected]:7999/npm/libs/...
Kewitschka's user avatar
  • 1,593
22 votes
3 answers
22k views

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

I am maintaining the following directory structure: /home/user/Desktop/ |-- app/ | |-- package.json | `-- server.js |-- ...
dibyendu's user avatar
  • 525
21 votes
10 answers
8k views

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",...
dpberry178's user avatar
20 votes
1 answer
17k views

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 <module> a script must be run before that module is installed. The ...
yawningphantom's user avatar
19 votes
12 answers
22k views

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 '...
Dayvvo's user avatar
  • 281
18 votes
3 answers
18k views

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 ...
Allen's user avatar
  • 4,669
16 votes
1 answer
39k views

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 ...
ΩmegaMan's user avatar
  • 30.8k
15 votes
1 answer
9k views

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 ...
relidon's user avatar
  • 2,272
15 votes
3 answers
8k views

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 <package_name> Yarn adds it ...
Erazihel's user avatar
  • 7,545
15 votes
1 answer
19k views

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 ...
lonewarrior556's user avatar
15 votes
1 answer
4k views

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: ...
jcollum's user avatar
  • 45.7k
15 votes
3 answers
8k views

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": "...
Hunsecker's user avatar
  • 151
14 votes
12 answers
70k views

Error: error:0308010C:digital envelope routines::unsupported (Node.js v19.4.0)

Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:71:19) at Object.createHash (node:crypto:140:10) at module.exports (D:\web development\...
javeria sohail's user avatar
14 votes
2 answers
19k views

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! ...
Neko's user avatar
  • 581
14 votes
3 answers
31k views

Pass parameter to npm run "my command" and use that parameter in my functions

Consider app.js const { doCoolStuff } = require("./api/myApi"); // grab param from command line into "myParam" doCoolStuff(myParam); ... // more code And Package.json: { &...
JAN's user avatar
  • 21.7k
14 votes
5 answers
4k views

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's user avatar
  • 709
14 votes
2 answers
4k views

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": "...
Leon Gaban's user avatar
  • 38.8k
13 votes
1 answer
14k views

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 { ... "...
Robert_QSS's user avatar
13 votes
1 answer
10k views

Output to command line within npm scripts?

I have a script in my package.json with the following code: "scripts": { "build": "postcss tailwind/tailwind.css -o css/cenic.tailwind.css", "watch": &...
4midori's user avatar
  • 478
13 votes
5 answers
22k views

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 ...
PzYon's user avatar
  • 2,983
13 votes
1 answer
2k views

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 : ...
Fraser's user avatar
  • 14.2k
13 votes
4 answers
2k views

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 ...
Undistraction's user avatar
12 votes
2 answers
11k views

Is there a way to use standard-version just to update the change log

I like standard-version as it updates the changelog using git commits but for a project I'm working on versioning is managed by another command - and HAS to stay like this. Is there a way of just ...
Arnold Rimmer's user avatar
12 votes
1 answer
8k views

In NPM, How to get the list of packages under a scope?

We are developing custom packages and each package is maintained under the scope. For example: @nest/common @nest/core @nest/microservice How to get the list of packages available in the ...
Thangaraja's user avatar

1
2 3 4 5
22