I\'m using npm run script to do tasks such as \"build\" and \"test\".
For example, my package.json
looks like the following:
{
\"name\
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:
>
that say what command you're running.npm ERR!
errors.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
.
There is an issue filed on npm: run-scripts are too noisy while used in development #8821 (also mentioned in a comment above)
In the discussion in that issue, a couple of people have mentioned creating an alias e.g. npr
(utilizing the --silent option gcampbell describes in his/her answer). Although --silent
can hide some npm type issues such as a malformed package.json, this seems like a reasonable solution for now.
alias npr='npm run --silent $*'
One other thing from that discussion which may be worth looking into, although it is yet another tool, is yarn which is described on a facebook blog post.
As others have noted, the problem with --silent
is you lose all output. There's another way that seems to work for most cases:
npm run something 2>/dev/null
If one of the binaries you are running happens to write to stderr, then that will be suppressed. But most node stuff writes to stdout, so it shouldn't be a problem.
Of course this will work only in a shell environment that supports output redirection.
Add file .npmrc
to project and put in the file loglevel=silent
.
In case if you've created a custom script and it returns with the NPM error (even there's no error), add
process.exitCode = 0;
at the end of the script to avoid error.