I get different results with a script with npm than calling the command directly - Node

I am setting up my environment on lint ES6 . I installed eslint and see it in my node_modules . In my node_modules/bin , I have an eslint command.

I can run the command and specify it in the directory, and I get no errors:

./node_modules/.bin/eslint src/main/webapp/js/lcrf

I can see all the lint errors that I need to fix.

I also added a command to my package.json :

  "scripts": { "lint": "eslint src/main/webapp/js/lcrf" }, 

Now I am trying to run a command using npm run lint . This lint my files, and I get the same number of lint errors, but then node errors. Here is my stack:

 npm ERR! Darwin 14.3.0 npm ERR! argv "node" "/usr/local/bin/npm" "run" "lint" npm ERR! node v0.12.2 npm ERR! npm v2.7.4 npm ERR! code ELIFECYCLE npm ERR! lcrf@0.0.0 lint: `eslint src/main/webapp/js/lcrf` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the lcrf@0.0.0 lint script 'eslint src/main/webapp/js/lcrf'. npm ERR! This is most likely a problem with the lcrf package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! eslint src/main/webapp/js/lcrf npm ERR! You can get their info via: npm ERR! npm owner ls lcrf npm ERR! There is likely additional logging output above. 

What can happen? What is the difference between the two ways that I execute a command?

+6
source share
1 answer

npm displayed above the non-zero return code from eslint . If you want lint errors to be a sign of "whoa, this should not have happened, red warning, something is really wrong if it is posted," then what you have.

If you are not using exit code (say, to stop the next build steps) and you just want the result to be only eslint output and not subsequent npm freak out, use this in your package.json :

 "lint": "eslint src/main/webapp/js/lcrf || exit 0" 

Note this in the "Best Practices" section of npm scripts docs :

Don't go out with a non-zero error code if you really don't mean it. With the exception of uninstallation scenarios, this will cause the npm action to fail and possibly be canceled. If the failure is minor or only prevents some additional features, then it is better to simply print a warning and exit successfully.

+9
source

Source: https://habr.com/ru/post/987093/


All Articles