Can I hide or silence "npm ERR!" output when using npm run script?
Add file .npmrc
to project and put in the file loglevel=silent
.
A variation on other posts related to this (but not enough cred to comment!), and a little quicker/convenient as a stop gap is that you can change the exit status of processes that npm is running in situ, so that it doesn't think it failed. Obviously this will not stop chained commands from running after it. Sh does boolean evaluation similar to JS, just add || true
on the end, e.g.:
"myscript": "eslint || true"
Hopefully this is also obvious enough that other devs can find it before they come looking for you!
You have to use npm run build --silent
.
This isn't documented in npm help
, npm help run
, or anything else obvious, but with some searching on the internet you can find out that apparently it is documented in npm help 7 config
. You can also use the loglevel
option in .npmrc
.
The --silent
(short: -s
) option suppresses:
- The two lines beginning with
>
that say what command you're running. npm ERR!
errors.- Creating an
npm-debug.log
if there's an error.
Note: using npm scripts to run other npm scripts may require you to use --silent
more than once. Example package.json
:
{
. . .
"scripts": {
"compile": "tsc",
"minify": "uglifyjs --some --options",
"build": "npm run compile && npm run minify"
}
}
If you do npm run build
and TypeScript finds an error, then you'll get the npm ERR!
from both scripts. To suppress them, you have to change the build script to npm run compile --silent && npm run minify
and run it with npm run build --silent
.