I have a problem with NPM. Lately, whenever I try to run scripts with npm it gives me an entire wall of errors, even when I know the scripts are correct and I can not figure out why...
package.json
{
"name": "testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
As you can see this is just generated right after running npm init and just hitting enter couple of times... and yet when I run npm run test I get this...
> testing#1.0.0 test C:\Users\user\Desktop\testing
> echo "Error: no test specified" && exit 1
"Error: no test specified"
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
npm ERR! node v7.4.0
npm ERR! npm v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! testing#1.0.0 test: `echo "Error: no test specified" && exit 1`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the testing#1.0.0 test script 'echo "Error: no test specified" && exit 1'.
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 testing package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! echo "Error: no test specified" && exit 1
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs testing
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls testing
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\user\Desktop\testing\npm-debug.log
As you can see in the error message, I have node v7.4.0 and npm v4.1.2... Previously I was running node v6.9.2, but I updated after getting this error and still no change... Also I don't know whether it matters much or not, but I am running windows 10. I have already tried the npm cache clear solution, but that did not work for me.
This is normal, when you run npm run test, it will execute the corresponding script in package.json, so this line
"test": "echo \"Error: no test specified\" && exit 1"
As you can see, it raises and error and exit with a status code different than 0 (exit 1), which is an error code.
You must change the test script by something else that really run tests.
Related
I'm trying to install NPM dependencies from a private GitLab instence.
So, I have my repo with basic files
And I added this dependencie in the package.json on my project
"node-demo-package": "https://oauth2:<ACCESS TOKEN>#gitlab.fullurl.git"
But, when I run npm install, I receive this error message:
npm ERR! code ENOPACKAGEJSON
npm ERR! package.json Non-registry package missing package.json: node-demo-package#https://oauth2:<ACCESS TOKEN>#gitlab.fullurl.git.
npm ERR! package.json npm can't find a package.json file in your current directory.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/arnaud.delante/.npm/_logs/2018-01-24T15_05_49_456Z-debug.log
Which I don't understand as there is a package.json as showed in the screenshot.
Here it is
{
"name": "demo-package",
"version": "1.0.0",
"description": "Test pasckage",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git#gitlab.fullurl.git"
},
"author": "Arnaud Delante",
"license": "MIT"
}
I already tried switching https by git+https but I get another error
npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t https://oauth2:<ACCES TOKEN>#gitlab.fullrul.git
npm ERR!
npm ERR! remote: You are not allowed to download code from this project.
npm ERR! fatal: unable to access 'https://oauth2:<ACCES TOKEN>#gitlab.fullrul.git': The requested URL returned error: 403
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/arnaud.delante/.npm/_logs/2018-01-24T17_19_16_677Z-debug.log
Which is weird because the token is correct.
Would you have any idea?
In package.json try to replace https:// by git+https://
doc : https://docs.npmjs.com/files/package.json#git-urls-as-dependencies
I am trying to setup a task in package.json
"scripts": {
"unit-test": "mocha './test/unit/**/*.spec.js'",
}
However when I run
npm run unit-test
the following errors are thrown in the console at the end of the run:
npm ERR! Darwin 16.6.0
npm ERR! argv "/Users/shreya.vakil/.nvm/v6.9.5/bin/node" "/Users/d.bubble/.nvm/v6.9.5/bin/npm" "run" "unit-test"
npm ERR! node v6.9.5
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! myapp#0.0.1-SNAPSHOT unit-test: `mocha './test/unit/**/*.spec.js'`
npm ERR! Exit status 1
However, if I change the command to
"scripts" : {
"unit-test": "mocha './test/unit/**/*.spec.js'; exit 0",
}
this error is not thrown. However, I am not sure if this is the right approach.
The original behavior is correct, if a little ugly - if your tests fail, Mocha returns an exit code of 1, which is technically an error. Your second example makes the output prettier, but it'll cause you issues if you try to integrate your build scripts into other tools (for example, Travis), as they won't be able to detect when your tests fail.
The best solution to this would be to get rid of the exit 0 and upgrade your version of NPM - the output was made much shorter in v4.6.1. You can do this by running the following command:
npm install npm -g
I installed jasmine npm module as global. Later on, with the purpose of sharing code and make easy for the team to have all dependencies, I installed jasmine locally to the project using --save-dev.
Issue is that it tries to exec from node_modules global one instead of local one.
Package.json
{
"name": "tdd",
"version": "1.0.0",
"description": "testing tdd practices",
"main": "index.js",
"scripts": {
"test": "$(npm bin)/jasmine"
},
"keywords": [
"test",
"tdd",
"jasmine",
"node"
],
"license": "ISC",
"devDependencies": {
"jasmine": "^2.4.1"
}
}
If my tests are passing I get no errors. In case a test does not pass, I get an error pointing to the global node_modules.
Albertos-MBP:TDD albertof$ npm run test
> tdd#1.0.0 test /Users/albertof/Projects/Web/TDD
> jasmine
Started
......FF
Failures:
1) Html Replacement Regex: should replace . in src attributes for <img src="./hello.jpg">
Message:
Expected '<img static/hello.jpg">' to be '<img src="static/hello.jpg">'.
Stack:
Error: Expected '<img static/hello.jpg">' to be '<img src="static/hello.jpg">'.
at Object.<anonymous> (/Users/albertof/Projects/Web/TDD/spec/htmlSpec.js:22:62)
8 specs, 1 failures
Finished in 0.015 seconds
npm ERR! Darwin 15.5.0
npm ERR! argv "/usr/local/bin/node" "/Users/albertof/npm-global/bin/npm" "run" "test"
npm ERR! node v6.0.0
npm ERR! npm v3.8.8
npm ERR! code ELIFECYCLE
npm ERR! tdd#1.0.0 test: `jasmine`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tdd#1.0.0 test script 'jasmine'.
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 tdd package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! jasmine
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs tdd
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls tdd
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/albertof/Projects/Web/TDD/npm-debug.log
What is the reason to try to execute from the global node_modules installed?
Running npm bin return the local one for the current project /Users/albertof/Projects/Web/TDD/node_modules/.bin
edit your package.json
"scripts": {
"test": "$(npm bin)/jasmine; exit 0"
}
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.
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."
}