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"
}
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 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.
I use node to write a command-line tool.
this is the index.js.
#!/usr/bin/env node
console.log('qiuyuntao');
this is the package.json
{
"name": "qiu",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"bin": {
"qyt": "index.js"
}
}
After I use command npm link, I can use command qyt anywhere. Now I want to unlink the command, I use npm unlink, it said
npm ERR! gentlyRm containing path /usr/local/lib/node_modules/qiu isn't under npm's control
npm WARN install:qiu#1.0.0 Refusing to delete: /usr/local/bin/qyt not in /usr/local/lib/node_modules/qiu
- qiu#1.0.0 node_modules/qiu
So, what should I do to unlink it?
Without knowing what version of npm you are using and if this is a bug thats being resolved I suspect that your global prefix is misconfigured perhaps.
At any rate the easiest solution is to manually remove the symlinks /usr/local/bin/qyt and /usr/local/lib/node_modules/qiu. If you are using the latest version of npm look into filing an issue, otherwise update (npm i -g npm).
Updating npm 3.9.5 > 4.0.5 fixed the same issue for me
Before update:
$ npm unlink
npm WARN install:#coolman/my-module#1.0.0 Refusing to delete /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod: ../lib/node_modules/my-module/index-cli.js symlink target is not controlled by npm /Users/coolman/.nvm/versions/node/v6.2.0/lib/node_modules/#coolman/my-module
- #coolman/my-module#1.0.0 node_modules/#coolman/my-module
$ npm --version
3.9.5
After update:
$ sudo npm install npm#latest -g
$ npm --version
4.0.5
$ npm unlink
- #coolman/my-module#1.0.0 node_modules/#coolman/my-module
And to repeat npm link, I needed to manually remove the bin:
$ npm link
npm WARN #my-company/my-module#1.0.0 No repository field.
npm ERR! Darwin 16.1.0
npm ERR! argv "/Users/coolman/.nvm/versions/node/v6.2.0/bin/node" "/Users/coolman/.nvm/versions/node/v6.2.0/bin/npm" "link"
npm ERR! node v6.2.0
npm ERR! npm v4.0.5
npm ERR! path /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod
npm ERR! code EEXIST
npm ERR! Refusing to delete /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod: ../lib/node_modules/my-module/index-cli.js symlink target is not controlled by npm /Users/coolman/my-company/tools/my-module
npm ERR! File exists: /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod
npm ERR! Move it away, and try again.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/coolman/my-company/tools/my-module/npm-debug.log
$ rm /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod
$ npm link
npm WARN #coolman/my-module#1.0.0 No repository field.
/Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod -> /Users/coolman/.nvm/versions/node/v6.2.0/lib/node_modules/#coolman/my-module/index-cli.js
/Users/coolman/.nvm/versions/node/v6.2.0/lib/node_modules/#coolman/my-module -> /Users/coolman/perkbox/tools/run-with-pb-session
I am new in the NodeJS world. I have created an loopback(strongloop) webapp, but after it I try to run the npm install command in the application's folder I get this output in the terminal (Ubuntu server 14.04 withd newest updates - in a vagrant instance)
vagrant#vagrant-ubuntu-trusty-64:/vagrant/example-app$ npm install
npm WARN package.json example-app#1.0.0 No license field.
npm WARN optional dep failed, continuing ycssmin#1.0.1
npm WARN deprecated jsonstream#1.0.3: use JSONStream instead
npm WARN optional dep failed, continuing request#2.62.0
npm WARN optional dep failed, continuing loopback-explorer#1.8.0
npm ERR! Linux 3.13.0-62-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! node v4.1.0
npm ERR! npm v2.14.3
npm ERR! path ../node-uuid/bin/uuid
npm ERR! code EPROTO
npm ERR! errno -71
npm ERR! syscall symlink
npm ERR! EPROTO: protocol error, symlink '../node-uuid/bin/uuid' -> '/vagrant/example-app/node_modules/loopback-datasource-juggler/node_modules/.bin/uuid'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Linux 3.13.0-62-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! node v4.1.0
npm ERR! npm v2.14.3
npm ERR! path npm-debug.log.2d5bb41273f18b2da30958b9aa61bfe6
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename 'npm-debug.log.2d5bb41273f18b2da30958b9aa61bfe6' -> 'npm-debug.log'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /vagrant/example-app/npm-debug.log
This is the generated package.json which has been generated by loopback framework:
{
"name": "example-app",
"version": "1.0.0",
"main": "server/server.js",
"scripts": {
"pretest": "jshint ."
},
"dependencies": {
"compression": "^1.0.3",
"cors": "^2.5.2",
"loopback": "^2.22.0",
"loopback-boot": "^2.6.5",
"loopback-datasource-juggler": "^2.39.0",
"serve-favicon": "^2.0.1"
},
"optionalDependencies": {
"loopback-explorer": "^1.1.0"
},
"devDependencies": {
"jshint": "^2.5.6"
},
"repository": {
"type": "",
"url": ""
},
"description": "example-app"
}
I have tried to run with sudo npm install but I have gotten exactly the same result.
Versions:
Node v4.1.0
Npm v2.14.3
Vagrant 1.7.4
Ubuntu Server 14.04.3 (with the newest updates)
Here is the npm-log file, it's very long.
If you know my mistake, do not hesitate, just answer :)
This is a problem with Vagrant/VirtualBox. Unfortunately, the synced/shared filesystem doesn't support symlinks.
If you don't require this functionality, the easiest thing to do is to just disable it in your Vagrantfile:
# ...
config.vm.synced_folder ".", "/vagrant", disabled: true
# ...
If you do require it, you may be able to find a work around now that you know it is a problem with symlink support, which npm uses for creating bins :-)
See https://docs.vagrantup.com/v2/synced-folders/basic_usage.html for more details.
The error happens, because your mounted shared directory (/vagrant) is on file system which doesn't support symbolic links.
To void this, you need to tell npm that your file system doesn't support symbolic links, e.g.
npm config set bin-links false
Source: npm doesn't work in vagrant at GH-7308
or by specifying --no-bin-links argument for npm install which will prevent npm from creating symlinks for any binaries the package might contain.
Alternative way is to append this to your package.json file, e.g.
"config": {
"bin-links": false
},
As said above, the synced/shared filesystem doesn't support symlinks.
SO, you can install node.js on your Windows host and execute npm install in the host code directory
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."
}