npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

"npm run lint" returns an error

Hello everybody,

hopefully someone can give some hints on how to solve this issue :wink:

First things first, I am on a MAC PRO and my node and npm versions are:

[myangular]master$ node -v
[myangular]master$ npm -v

I am using jshint to lint my code. I did run:

npm install --save-dev jshint

so now I have my jshint module in my myangular project. The project structure is:


If you want to see the details you can find it here:

When I run:

[myangular]$ ./node_modules/jshint/bin/jshint src

all goes well. If I have a semicolon syntax error in hello.js, I’ll get:

[myangular]master$ ./node_modules/jshint/bin/jshint src
src/hello.js: line 2, col 25, Missing semicolon.

1 error

which is perfect. In my package.json I have a lint script:

  "name": "my-own-angularjs",
  "version": "0.1.0",
  "description": "",
  "main": "index.js",
  "directories": {
    "test": "test"
  "scripts": {
    "lint": "jshint src"
  "author": "Luca Leone",
  "license": "MIT",
  "devDependencies": {
    "jshint": "^2.10.2"

If the semicolon is not missing in hello.js when I run:

[myangular]master$ npm run lint

> my-own-angularjs@0.1.0 lint /Users/luc4leone/myangular
> jshint src

But if the semicolon is missing, I’ll get:

[myangular]master$ npm run lint

> my-own-angularjs@0.1.0 lint /Users/luc4leone/myangular
> jshint src

src/hello.js: line 2, col 25, Missing semicolon.

1 error
npm ERR! errno 2
npm ERR! my-own-angularjs@0.1.0 lint: `jshint src`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the my-own-angularjs@0.1.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!     /Users/luc4leone/.npm/_logs/2019-08-23T15_48_15_055Z-debug.log

And here’s the log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'lint' ]
2 info using npm@6.10.3
3 info using node@v11.10.0
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle my-own-angularjs@0.1.0~prelint: my-own-angularjs@0.1.0
6 info lifecycle my-own-angularjs@0.1.0~lint: my-own-angularjs@0.1.0
7 verbose lifecycle my-own-angularjs@0.1.0~lint: unsafe-perm in lifecycle true
8 verbose lifecycle my-own-angularjs@0.1.0~lint: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/luc4leone/myangular/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/luc4leone:
9 verbose lifecycle my-own-angularjs@0.1.0~lint: CWD: /Users/luc4leone/myangular
10 silly lifecycle my-own-angularjs@0.1.0~lint: Args: [ '-c', 'jshint src' ]
11 silly lifecycle my-own-angularjs@0.1.0~lint: Returned: code: 2  signal: null
12 info lifecycle my-own-angularjs@0.1.0~lint: Failed to exec lint script
13 verbose stack Error: my-own-angularjs@0.1.0 lint: `jshint src`
13 verbose stack Exit status 2
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:326:16)
13 verbose stack     at EventEmitter.emit (events.js:197:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:197:13)
13 verbose stack     at maybeClose (internal/child_process.js:984:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid my-own-angularjs@0.1.0
15 verbose cwd /Users/luc4leone/myangular
16 verbose Darwin 17.0.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "lint"
18 verbose node v11.10.0
19 verbose npm  v6.10.3
20 error code ELIFECYCLE
21 error errno 2
22 error my-own-angularjs@0.1.0 lint: `jshint src`
22 error Exit status 2
23 error Failed at the my-own-angularjs@0.1.0 lint script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]

That means I get an error only when there’s a syntax problem.**

I checked the environment variables

[myangular]master$ npm run env | grep "^PATH"

where I see the correct path to the jshint executable.


I guess npm creates the env and the modules/.bin dir. So everything looks OK, but the issue is there.

Most shell commands set the shell exit code (status) when they detect a problem. This is what jshint is doing, and is what I expect when a program like this finds something to report.

npm run displays error information when it detects the exit code was set by the script. Since npm does not know what the script displayed and how clear the failure was, it makes sure you know something went wrong!

When you are running a script and do not want the extra noise, you can use --silent.

$ npm run lint --silent
src/hello.js: line 2, col 25, Missing semicolon.

1 error

You can also suppress the error status code in the script. This may be convenient for scripts you only run manually, but means the script less useful for chaining together commands or failing a build if there are lint problems etc.

"lint": "jshint src || true"

That means that it was working as intended. My bad thinking npm run lint should have worked as ./node_modules/jshint/bin/jshint src

Thanks a lot for the explanation @shadowspawn! :smile: :sunny: