简体   繁体   中英

NPM unable to install browserify globally

I'm unable to install Browserify (or anything) globally. I'm able to install things non-globally without issue.

background: I'm running CentOS 6.6 on a corporate network behind a proxy. I installed Node.js using "yum" as root.

$ sudo yum -y install nodejs

and npm (which wasn't installed with nodejs for some reason):

$ sudo yum -y install nodejs npm

This installed Node.js and NPM to the directories:

$ which node
/usr/bin/node

$ which npm
/usr/bin/npm

and put the "node_modules" under /usr/lib/node_modules.

Like I said, I'm behind a proxy so I set the "proxy" and "https-proxy" config properties to the correct values.

When I tried to install browserify (as specified on their site )

$ npm install -g browserify

I received an error

...npm ERR! stack Error: EACCES, mkdir '/usr/lib/node_modules/browserify'...

So I "chowned" the /usr/lib/node_modules dir to give me access to mkdirs in node_modules:

$ sudo chown -R $USER /usr/lib/node_modules

The error: Now when I try to install browserify globally I get a different error:

npm ERR! Error: EACCES, symlink '../lib/node_modules/browserify/bin/cmd.js'
npm ERR!  { [Error: EACCES, symlink '../lib/node_modules/browserify/bin/cmd.js']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '../lib/node_modules/browserify/bin/cmd.js' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Linux 2.6.32-431.el6.x86_64
npm ERR! command "node" "/usr/bin/npm" "install" "-g" "browserify"
npm ERR! cwd /usr/lib/node_modules
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.3.6
npm ERR! path ../lib/node_modules/browserify/bin/cmd.js
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '../lib/node_modules/browserify/bin/cmd.js'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /usr/lib/node_modules/npm-debug.log
npm ERR! not ok code 0

Is there anything special that I need to change to allow NPM to create the symlink?

Also, I tried running the install as root but it just sits there until eventually timing out:

...npm ERR! network tunneling socket could not be established, cause=read ECONNRESET...

I recently experienced this issue. Global modules should be installed as root (sudo). Where my process was failing (similar to yours) was the timeout when running this as root. This was due to the fact the NPM was using the "git" protocol. To get the packages to install, I had to run the following to my git config.

git config --global url."https://".insteadOf git://

This solved my problem.

I was finally able to install modules globally using npm.

What I did:

I had to use sudo and set the proxy/https proxy in several places. I followed the advice from this blog: http://wil.boayue.com/blog/2013/06/14/using-npm-behind-a-proxy/ .

I set the following variables in ~/.bashrc and exported them:

  • http_proxy
  • https_proxy
  • npm_config_proxy
  • npm_config_https_proxy

I also added them to env_keep using visudo (so they'd be available to sudo).

I then set the proxy and https-proxy config settings on npm using:

$ npm config set proxy http://<proxy>:<port>
$ npm config set proxy http://<proxy>:<port>

I'm not sure if all of this was necessary but it worked for me. Also, at one point I realized that I had the incorrect proxy and had to change it in several places (so be sure to double check that).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM