How to prevent cascading of error codes when "aliasing" scripts (i.e script calling another script)

So I’ve got some scripts in my package.json:

{
   ...
  "scripts": {
    "build": "cd ./configs && wp --config ./webpack.prod.mjs",
    "lint": "npm run lint:all",
    "lint:all": "eslint \"**/*.{t,j}s{x,}\"",
    "lint:staged": "lint-staged",
    "serve": "cd ./configs && wp --config ./webpack.dev.mjs",
    "test": "jest"
  },
 ...
}

Notice that lint just calls lint:all - this is b/c it’s serving as the most common expectation when you say “lint that project!” (specifically, .lintstagedrc calls eslint “typically”, unless the changed file is .eslintrc or .eslintignore, in which case it calls npm run lint:all)

This works, but annoyingly results in two error outputs, since lint:staged returns an error code, which lint then returns:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @techweek/techweek-lex-lambda@0.0.0 lint:all: `eslint "**/*.{t,j}s"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @techweek/techweek-lex-lambda@0.0.0 lint:all script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\G-Rath\AppData\Roaming\npm-cache\_logs\2019-06-11T04_41_37_940Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @techweek/techweek-lex-lambda@0.0.0 lint: `npm run lint:all`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @techweek/techweek-lex-lambda@0.0.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\G-Rath\AppData\Roaming\npm-cache\_logs\2019-06-11T04_41_38_018Z-debug.log

Due to the nature of the error, it’s been really hard trying to research, so I’m asking here:

Is there anyway to suppress or roll this up? I know npm doesn’t want to provide a way to suppress the message entirely, which I’m fine with - it’s just having it shown multiple times in a row for the same error code is very cluttering.

There is an option when you are invoking npm yourself in the script:

You can use the --silent flag to prevent showing npm ERR! output on error.

https://docs.npmjs.com/cli/run-script.html

Oh thanks.

I didn’t think that was every implemented, as I remember reading some comments on github a few years back from the npm team - they didn’t want to let you silence those error messages b/c otherwise it could look like npm was at fault.

But so I’ll give that a try - thanks!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.