Reputation: 24610
I'm using npm run script to do tasks such as "build" and "test".
For example, my package.json
looks like the following:
{
"name": "fulfillment-service",
"version": "1.0.0",
"description": "Endpoint for CRUD operations on fulfillment status",
"main": "src/server.js",
"scripts": {
"build": "tsc",
"test": "tape tests/*.js"
},
"dependencies": {},
"devDependencies": {
"typescript": "^1.8.10"
}
}
When I run npm run build
and it is successful, the output is the following:
> [email protected] build d:\code\fulfillment-service
> tsc
When I run npm run build
and it fails, the output is the following:
> [email protected] build d:\code\fulfillment-service
> tsc
src/server.ts(51,81): error TS2339: Property 'connection' does not exist on type 'IncomingMessage'.
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.2.1
npm ERR! npm v3.9.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script 'tsc'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the fulfillment-service package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs fulfillment-service
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls fulfillment-service
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! d:\code\fulfillment-service\npm-debug.log
This fills the entire console with useless information, and I have to scroll to the top to see why it failed.
Is there anyway to hide/silence the lines that start with npm ERR!
during development?
Upvotes: 49
Views: 18782
Reputation: 111
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!
Upvotes: 4
Reputation: 40454
Add file .npmrc
to project and put in the file loglevel=silent
.
Upvotes: 12
Reputation: 1887
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.
Upvotes: 0
Reputation: 548
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.
Upvotes: 1
Reputation: 2251
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.
Upvotes: 1
Reputation: 1272
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
.
Upvotes: 50