package.json vs. "npm install %s -g" - node.js

A package.json example:
{
"devDependencies": {
"jasmine-node": ""
}
}
It just won't work. Some errors like the following will appear:
npm ERR! error rolling back Error: UNKNOWN, unlink '/vagrant/x/node_modules/jasmine-node/node_modules/jasmine-reporters/ext/env.rhino.1.2.js'
npm ERR! error rolling back jasmine-node#1.14.5 { [Error: UNKNOWN, unlink '/vagrant/x/node_modules/jasmine-node/node_modules/jasmine-reporters/ext/env.rhino.1.2.js']
npm ERR! error rolling back errno: -1,
npm ERR! error rolling back code: 'UNKNOWN',
npm ERR! error rolling back path: '/vagrant/x/node_modules/jasmine-node/node_modules/jasmine-reporters/ext/env.rhino.1.2.js' }
npm ERR! Error: UNKNOWN, symlink '../coffee-script/bin/coffee'
npm ERR! If you need help, you may report this entire log,
npm ERR! including the npm and node versions, at:
npm ERR! http://github.com/npm/npm/issues
But if I do npm install jasmine-node -g, everything install and works seamlessly and I can't see why.
Can someone clarify this question for me?

You can try this:
sudo npm install jasmine-node#1.14.2 -g
Current version is 1.14.3, so it is one version behind.
In package.json try:
{
"devDependencies": {
"jasmine-node": ">=1.14.3"
"jasmine-reporters": "~1.0.0",
}
}

Remove that line from package.json and do npm install --save-dev jasmine-node that will install it and add the correct line in your devDependencies.

Related

npm install only fails when used with child_process.exec

Running this in my terminal:
npm i --save-dev typescript 'https://gitpkg.now.sh/pylonbot/pylon-sdk-types/runtime' 'https://gitpkg.now.sh/pylonbot/pylon-sdk-types/runtime-discord'
Installs the packages as would be expected. But, when I try to use child_process's execSync to install these packages the installation fails.
The code:
try {
child_process.execSync(`npm i --save-dev typescript 'https://gitpkg.now.sh/pylonbot/pylon-sdk-types/runtime' 'https://gitpkg.now.sh/pylonbot/pylon-sdk-types/runtime-discord'`);
} catch(e) {
console.log(e);
process.exit();
} finally {
console.log('It worked!');
}
Output:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\me\test\'https:\gitpkg.now.sh\pylonbot\pylon-sdk-types\runtime'/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\me\test\'https:\gitpkg.now.sh\pylonbot\pylon-sdk-types\runtime'\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
Interestingly, it only fails when the gitpkgs are included (gitpkg is a tool that lets you install packages from github subdirs)
Sorry in advance if this is something stupid, but I can't figure it out.
For whatever reason, removing the quotes around the gitpkg link fixed this.

npm ERR! cb() never called! npm ERR! This is an error with npm itself. Please report this error at: npm ERR

npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://github.com/npm/cli/issues>
npm ERR! A complete log of this run can be found in:
npm ERR! /home/abhijith/.npm/_logs/2021-05-12T16_20_42_200Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.
Deleting generated file... package.json
getting error trying to install react { npx react-create-app app}
i try sudo npm cache, sudo npm cache --force clean but still getting same error
this is an error related to npm package and installing latest version of npm worked at me :
npm install -g npm#latest
My problem also got resolved after installing the latest version of npm. But I needed to use sudo before npm install -g npm#latest. Otherwise there were some warnings and errors of access denied.

Cannot change npm global location

looks like i messed up something with npm, and i don't know what should i do.
environments:
- Amazon Linux (EC2)
this is the story:
I installed nodejs with yum: "yum install nodejs npm --enablerepo=epel" on my server few months ago.
and then, i knew that there were node version manager(nvm), so i removed my node.js and install the nvm, and then installed latest node.js
but looks like there were something messed up with nvm settings(recently realized) so i removed nodejs with nvm, and then removed nvm.
then i re-installed node.js with same above with yum command. it looks fine, nodejs worked well, but there was big trouble with npm. i checked the location of global modules with command "npm root -g" as normal user(ec2-user), it prints
npm ERR! Error: EACCES, mkdir '/root/.nvm/versions/node/v5.5.0'
npm ERR! { [Error: EACCES, mkdir '/root/.nvm/versions/node/v5.5.0']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/root/.nvm/versions/node/v5.5.0' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 4.1.13-19.31.amzn1.x86_64
npm ERR! command "node" "/usr/bin/npm" "prefix"
npm ERR! cwd /home/ec2-user/modernator
npm ERR! node -v v0.10.42
npm ERR! npm -v 1.3.6
npm ERR! path /root/.nvm/versions/node/v5.5.0
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/root/.nvm/versions/node/v5.5.0'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ec2-user/modernator/npm-debug.log
npm ERR! not ok code 0
so i logged in to admin, and typed same command "npm root -g", it prints:
/usr/lib/node_modules
looks like something is messed up when i removed nvm. everytime i tried to change npm prefix or just try to get any config from npm as normal user, always fail with same error messages!
but if i try with sudo("sudo npm root -g"), it says "/usr/lib/node_modules".
i spend to solve this problem for days but i still working on. and still i don't know even what should i do. every posts found from google not worked. i removed and installed nodejs plenty of times, but not worked. please god, if someone know how to solve this, please give me a advice.
You don't have access by default to root resources.
When you perform this:
npm root -g
It tries it for root user, i bet you need to change user:
npm $USER -g

Npm errors while I try to install dependencies in loopback (strongloop) webapp

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

npm local install fails on first try

Background
I have package.json with a bunch of development dependencies.
I use local install i.e. npm install with my package.json
node -v v0.10.26
npm -v 1.4.4
Windows 7 x32bit
Problem
On fresh first try with no ./node_modules present (i.e. fresh) I get various errors.
Some of them are related to npm_cache and locks saying that I need to run as Administrator. Why?
Why does the subsequent npm install succeeds.
Questions
Why should subsequent install should succeed ? I am not interested why they fail - there could be various reasons and perhaps each need to be dealt with well.
Can deleting local ./node_modules folder manually cause any issues that are relate to this topic ?
Updates: Added following sections as requested
Logs/References
package.json
{
"name": "XXXXX-XXXX-XXXX",
"version": "0.0.2",
"dependencies": {
"angular": "1.3.0-beta.14",
"ng-grid": "2.0.11",
"json3": "~3.2.6",
"es5-shim": "~2.1.0",
"jquery": "~1.10.2",
"bootstrap": "~3.0.3",
"angular-resource": "1.3.0-beta.14",
"angular-route": "1.3.0-beta.14",
"angular-bootstrap": "~0.11.0",
"jquery-ui": "~1.10.4",
"angular-animate": "1.3.0-beta.14",
"tinymce": "~4.1.2",
"angular-ui-tinymce": "~0.0.5"
},
"devDependencies": {
"angular-mocks": "1.3.0-beta.14",
"angular-scenario": "1.3.0-beta.14"
},
"resolutions": {
"angular": "1.3.0-beta.14",
"tinymce": "~4.1.2",
"angular-mocks": "1.3.0-beta.14",
"angular-scenario": "1.3.0-beta.14"
}
}
npm install output snippet
npm ERR! error rolling back Error: EPERM, unlink 'C:\Users\REPLACED_PATH\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-pngquant\node_modules\pngquant-bin\node_modules\bin-build\node_modules\download\node_modules\download-status\node_modu
les\lpad-align\node_modules\max-component\node_modules\to-function\node_modules\remove-try-require\node_modules\ast-transform\node_modules\escodegen\escodegen.bro
wser.min.js'
npm ERR! error rolling back download#3.1.0 { [Error: EPERM, unlink 'C:\Users\REPLACED_PATH\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-pngquant\node_modules\pngquant-bin\node_modules\bin-build\node_modules\download\node_modules\downlo
ad-status\node_modules\lpad-align\node_modules\max-component\node_modules\to-function\node_modules\remove-try-require\node_modules\ast-transform\node_modules\esco
degen\escodegen.browser.min.js']
npm ERR! error rolling back errno: 50,
npm ERR! error rolling back code: 'EPERM',
npm ERR! error rolling back path: 'C:\\Users\\my.userid\\Documents\\clients\\merge.0.0.1\\tps-clients\\tps-web-app\\node_modules\\grunt-contrib-imagemin\\nod
e_modules\\imagemin\\node_modules\\imagemin-pngquant\\node_modules\\pngquant-bin\\node_modules\\bin-build\\node_modules\\download\\node_modules\\download-status\\
node_modules\\lpad-align\\node_modules\\max-component\\node_modules\\to-function\\node_modules\\remove-try-require\\node_modules\\ast-transform\\node_modules\\esc
odegen\\escodegen.browser.min.js' }
npm http 200 https://registry.npmjs.org/ast-types
npm http GET https://registry.npmjs.org/source-map/0.1.32
npm http 304 https://registry.npmjs.org/source-map/0.1.32
npm http GET https://registry.npmjs.org/estraverse
npm http GET https://registry.npmjs.org/is-relative
npm http GET https://registry.npmjs.org/wrappy
npm http 304 https://registry.npmjs.org/estraverse
npm http 304 https://registry.npmjs.org/is-relative
npm http 304 https://registry.npmjs.org/wrappy
npm http GET https://registry.npmjs.org/ast-types/-/ast-types-0.3.38.tgz
npm http GET https://registry.npmjs.org/cls/-/cls-0.1.5.tgz
npm http GET https://registry.npmjs.org/private/-/private-0.1.5.tgz
npm ERR! Error: ENOENT, lstat 'C:\Users\REPLACED_PATH\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-pngquant\node_modules\pngquant-bin\node_modules\bin-build\node_modules\download\node_modules\request\node_modules\http-signature\node_mod
ules\asn1'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\My_Data\\devenv\\node\\\\node.exe" "C:\\My_Data\\devenv\\node\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd C:\Users\REPLACED_PATH
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.4
npm ERR! path C:\Users\REPLACED_PATH\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-pngquant\node_modules\pngquant-bin\node_modules\bin-build\node_modules\download\node_modules\request\node_modules\http-signature\node_modules\asn1
npm ERR! fstream_path C:\Users\REPLACED_PATH\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-pngquant\node_modules\pngquant-bin\node_modules\bin-build\node_modules\download\node_modules\request\node_modules\http-signature\node_modules\asn1
npm ERR! fstream_unc_path \\?\C:\Users\REPLACED_PATH\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-pngquant\node_modules\pngquant-bin\node_modules\bin-build\node_modules\download\node_modules\request\node_modules\http-signature\node_modu
les\asn1
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code ENOENT
npm ERR! errno 34
As commented by #Julian H. Lam the problem was the way Windows 7 OS treats the files and the folder permissions.
After running the cmd as Administrator I am no longer seeing this.

Resources