Skip to main content

All Questions

Tagged with
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
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
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
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
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
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
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
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
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
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
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
11 votes
4 answers
20k views

How to rename file with npm script

I am using copyfiles as an npm scirpt copyfiles -u 2 /src/app/conf.dev.json dist/config/ but in the end I want to get the file renamed How would you rename the input file in to something like conf....
Sergino's user avatar
  • 10.6k
11 votes
2 answers
10k views

Generating sourcemaps with npm scripts using node-sass and postcss autoprefixer

Is it possible to generate fully working sourcemaps using node-sass and postcss autoprefixer when piping output from one to another? I currently have the following in package.json: "scripts": { "...
baseten's user avatar
  • 1,412
11 votes
1 answer
6k views

How can I get live-reload on a local npm package in a monorepo?

I'm setting up a monorepo workspace for a Vue 3 (vite + ts), cloud functions, & shared-lib (shared functions and ts interfaces etc.). I can get the import of my local shared-lib folder to work. I ...
CVE's user avatar
  • 161
10 votes
2 answers
5k views

Can I run two ongoing npm commands in 1 terminal

I have these 2 commands in my npm scripts "scripts": { "webpack": "webpack --config webpack.config.js --watch", "server": "nodemon server.js", } As you can see, one runs webpack every time I save a ...
TheGreyBearded's user avatar
10 votes
1 answer
3k views

Match multiple file extensions in npm script

I have an npm script where I want to match both ts and tsx file extensions... something like below: "test": "mocha ..... app/test/**/*.spec.{ts,tsx}" However, the above syntax doesn't work. What's ...
sir_thursday's user avatar
  • 5,379
10 votes
2 answers
23k views

My React App has unfixable High Severity warnings, how do I fix this?

I cloned my repo for a react app. Ran npm i Received 3 high severity warnings. On attempt to fix (npm audit fix --force) I get 31 vulnerabilities in total Here are the warnings: npm WARN deprecated ...
Scotch's user avatar
  • 153
10 votes
1 answer
2k views

Default values for environment variables in .npmrc

Does somebody know how to set default environment variables in .npmrc files ? I tried to do this: registry=${myEnvVariable:-https://myregistry.com} and this: defaultRegistry=https://myregistry.com ...
bran4's user avatar
  • 123
9 votes
1 answer
6k views

Apply visual styling to echo commands used in npm scripts via package.json

Have recently put together a build tool with npm and package.json scripts, and I have a few echo commands to state which parts of the pipeline are currently running. For example (from my package.json)...
Glynn Smith's user avatar
9 votes
1 answer
3k views

Why does running "npm run <script>" as root switch user?

I setup a new project inside an alpine image (node:16-alpine), in /app2, with the following structure: - node_modules - .bin - dummy - package.json package.json: { ... "scripts": {...
Kicsi's user avatar
  • 1,123
9 votes
1 answer
2k views

How to set npm script to blank via the command line?

When I ran npm set-script prepare "" (using npm version 8.15.0 in a Windows command prompt), a warning was output: npm WARN set-script set-script is deprecated, use `npm pkg set scripts....
Steve Chambers's user avatar
9 votes
1 answer
4k views

npm package.json: How to wrap long single function scripts?

I have created an npm package script for npx depcheck and one of its parameters, --ignore, its value is getting very long and I expect will get longer. "audit:depcheck": "npx depcheck --specials=bin -...
Jeff's user avatar
  • 1,799
8 votes
3 answers
14k views

npm run scripts does not working

I have just initialized a new project with Node.js and trying making the scripts in package.json file to be working. For example I have the next package.json file: { "name": "my-app-name", "...
Raz Buchnik's user avatar
  • 8,201
8 votes
4 answers
33k views

NPM install hangs when installing packages

I currently using a project. It works fine but the problem when I remove the project files(except node_modules) to another folder or GitHub, reinstalling packages via npm is not successful. It always ...
Vugar Abdullayev's user avatar

1
2 3 4 5
15