npm run cmd fails while cmd on command line works - node.js

In my HTTP Status Check project:
If I run node_modules/.bin/jshint . I get:
$ node_modules/.bin/jshint .
test/inAdapters_fileAdapter.js: line 73, col 31, Missing semicolon.
1 error
It executes correctly and produces the expected output: 1 error.
But if I add that command to package.json and try and run it through npm run then it works and produces the expected output but also follows that with a bunch of errors:
$ npm run jshint
> http-status-check#0.0.5 jshint /home/guy/source/http-status-check
> jshint .
test/inAdapters_fileAdapter.js: line 73, col 31, Missing semicolon.
1 error
npm ERR! Linux 3.13.0-24-generic
npm ERR! argv "node" "/home/guy/local/bin/npm" "run" "jshint"
npm ERR! node v0.10.31
npm ERR! npm v2.0.0
npm ERR! code ELIFECYCLE
npm ERR! http-status-check#0.0.5 jshint: `jshint .`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the http-status-check#0.0.5 jshint script.
npm ERR! This is most likely a problem with the http-status-check package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! jshint .
npm ERR! You can get their info via:
npm ERR! npm owner ls http-status-check
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/guy/source/http-status-check/npm-debug.log
This is how it's defined in package.json:
"scripts": {
"jshint": "node_modules/.bin/jshint .",
},
What have I done wrong?

Don't exit with a non-zero error code unless you really mean it. Except for uninstall scripts, this will cause the npm action to fail, and potentially be rolled back. If the failure is minor or only will prevent some optional features, then it's better to just print a warning and exit successfully.
From https://www.npmjs.org/doc/misc/npm-scripts.html
Use:
node_modules/.bin/jshint .; true
Or write a wrapper that calls jshint and then ignores the exit code and exits successfully with a exit code of zero.

Related

Problem running Plutus Playground Client on MacOS

I am encountering a problem when trying to run the Plutus Playground through Nix on MacOS.
I tried using the last available tag v2021-12-20, but I am getting the following error when I try to run the Plutus Playground Client in nix-shell:
nix-shell:~/cardano/plutus-apps/plutus-playground-client]$ npm run start
> plutus-playground-client#1.0.0 start /Users/matt/cardano/plutus-apps/plutus-playground-client
> plutus-playground-generate-purs && npm install && npm run install:spago && npm run build:webpack:dev
/nix/store/2nr8xfy3zqdgxfmxlc3r48gijfdwbnrf-plutus-playground-generate-purs/bin/plutus-playground-generate-purs: line 6: /bin/plutus-playground-server: No such file or directory
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! plutus-playground-client#1.0.0 start: `plutus-playground-generate-purs && npm install && npm run install:spago && npm run build:webpack:dev`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the plutus-playground-client#1.0.0 start 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/matt/.npm/_logs/2021-12-20T18_27_49_943Z-debug.log
It seems similar to Plutus Playground Client cannot run, but I couldn't find anything to help run it.
My Nix config:
uild-users-group = nixbld
substituters = https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
sandbox = false
system = x86_64-darwin
extra-platforms = x86_64-darwin aarch64-darwin
I am running it on an M1 Mac.

Trouble building react-webapp with ESLint; ESLint couldn't find the config "developit" to extend from

My react app works as normal using npm start, but when I try npm run build I got trouble.
Oops! Something went wrong! :(
ESLint: 6.8.0.
ESLint couldn't find the config "developit" to extend from. Please check that the name of the config is correct.
The config "developit" was referenced from the config file in "/home/user/beregning-innsikt/beregning-innsikt-webapp/src/main/webapp/node_modules/#babel/preset-modules/package.json".
If you still have problems, please stop by https://gitter.im/eslint/eslint to chat with the team.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! beregning-innsikt-webapp#2.0.0 lint: `eslint 'src/**/*{.ts,.tsx}'`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the beregning-innsikt-webapp#2.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! /home/user/.npm/_logs/2020-08-11T08_20_44_975Z-debug.log
ERROR: "lint" exited with 2.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! beregning-innsikt-webapp#2.0.0 prebuild: `npm-run-all clean lint && aurora-mi git`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the beregning-innsikt-webapp#2.0.0 prebuild 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! /home/user/.npm/_logs/2020-08-11T08_20_45_002Z-debug.log
The Babel config file contains this:
"eslintConfig": {
"extends": "developit",
"rules": {
"no-console": 0,
"new-cap": 0
}
},
I have tried node v 13.7.0 and 14.1.0.
Does anybody know how to solve this problem?
Seems like it is linting node_modules too
To fix this you can create file .eslintignore in your root directory and add node_modules/ folder to your eslintignore file

npm run npm bin from within the same package

I'm working on extending open source raml2html library, which consumes raml contract to generate html docs. Key facts:
the library has a binary placed in bin/raml2html file; th ebinary is stated in package.json as follows:
"bin": {
"raml2html": "./bin/raml2html"
}
when npm install'ed by the users, the program is executed
I use the binary to update examples: both source .raml files and output .html files are kept in the repo. I'm using the binary with ./bin/raml2html examples/example.raml -o examples/example.html with git bash under windows and it works fine.
however, I want to wrap this commands as npm run script, so I define:
"scripts": {
...
"examples:example": "./bin/raml2html examples/example.raml -o examples/example.html",
"examples:github": "./bin/raml2html examples/github.raml -o examples/github.html",
"examples": "npm run examples:example && examples:github"
},
and when I call either npm run examples or npm run examples:example, both fail the same way:
`
$ npm run examples:example
> raml2html#2.4.0 examples:example C:\Users\tomasz.ducin\Development\GitHub\raml2html
> ./bin/raml2html examples/example.raml -o examples/example.html
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "examples:example"
npm ERR! node v4.4.3
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! raml2html#2.4.0 examples:example: `./bin/raml2html examples/example.raml -o examples/example.html`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the raml2html#2.4.0 examples:example script './bin/raml2html examples/example.raml -o examples/example.html'.
npm ERR! This is most likely a problem with the raml2html package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./bin/raml2html examples/example.raml -o examples/example.html
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs raml2html
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls raml2html
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\tomasz.ducin\Development\GitHub\raml2html\npm-debug.log
It says that '.' is not recognized as an internal or external command - well, that's true, ./bin/raml2html is not how I should do that on windows. But it's being ran under node.js/npm layer and package.json:bin can understand this syntax. I get confused with that.
The question is: how can I set up npm run scrpt to use the binary inside the same package?

I am getting different results running a script with npm than calling the command directly - Node

I am setting up my environment to lint ES6. I installed eslint and can see it in my node_modules. In my node_modules/bin directory, I have the command eslint.
I can run the command and point it at the directory and I get no errors:
./node_modules/.bin/eslint src/main/webapp/js/lcrf
I can see all of the linting errors that I need to fix.
I have also added the command into my package.json:
"scripts": {
"lint": "eslint src/main/webapp/js/lcrf"
},
Now I try to run the command with npm run lint. It lints my files and I get the same number of linting errors, but then node errors out. Here is my stacktrace:
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 would cause this to happen? What is the difference in the 2 ways that I am running the command?
npm is freaking out over the non-zero return code from eslint. If you want lint errors to be an indication of "whoa, that's not supposed to happen, red alert, something is really wrong if this got published" then that's what you've got.
If you don't use the exit code (say, to stop subsequent build steps) and you just want the output to be just the eslint output and no subsequent npm freak out, use this in your package.json:
"lint": "eslint src/main/webapp/js/lcrf || exit 0"
Note this in "Best Practices" section of the npm scripts docs:
Don't exit with a non-zero error code unless you really mean it. Except for uninstall scripts, this will cause the npm action to fail, and potentially be rolled back. If the failure is minor or only will prevent some optional features, then it's better to just print a warning and exit successfully.

npm error ELIFECYCLE while running the test

I am using mocha-phantomjs setup for unit testing. I have following package.json scriot to run the tests.
"scripts": {
"test": "npm run testFlickr",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html"
}
This run ok in browser. And when I run the command npm testin cmd, the test run alright but it also gives following error
3 passing (5s)
6 failing
npm ERR! flickr-test# testFlickr: `mocha-phantomjs ./test/FlickrTest.html`
npm ERR! Exit status 6
npm ERR!
npm ERR! Failed at the flickr-test# testFlickr script.
npm ERR! This is most likely a problem with the flickr-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mocha-phantomjs ./test/FlickrTest.html
npm ERR! You can get their info via:
npm ERR! npm owner ls flickr-test
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "testFlickr"
npm ERR! cwd C:\Users\user\Desktop\test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Users\user\Desktop\test\npm-debug.log
npm ERR! not ok code 0
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
Please can anyone tell me how can I resolve this error.
I was having this same problem, and what fixed it for me was when I run my unit tests, do NOT use
npm run test
instead use:
npm test
When running npm test it squelches ELIFECYCLE errors so you never encounter this experience.
Reference to code
Once you move a test script to a different script-name you'll start seeing ELIFECYCLE errors.
My fix is to add a exit 0 to the end of the command. For your code it would look like this:
"scripts": {
"test": "npm run testFlickr",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html; exit 0"
}
And when I run the command npm test in cmd, the test run alright
No they aren't. You have 6 failing tests. The exit code of mocha-phantomjs is equal to the number of failing tests. Run mocha-phantomjs ./test/FlickrTest.html directly and see what is failing. Realize the PhantomJS is a bit different than your browser - you may have to debug it.
Your script setup is odd. You should just have:
"scripts": {
"test": "mocha-phantomjs ./test/FlickrTest.html"
}
Then the odd node errors should go away.
This is a problem when using npm run, it has to do with Mocha exiting with code !== 0 whenever a test fails. If you are on Windows try this:
"scripts": {
"test": "npm run testFlickr || ECHO.",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html || ECHO."
}

Resources