简体   繁体   English

NPM无法全局安装browserify

[英]NPM unable to install browserify globally

I'm unable to install Browserify (or anything) globally. 我无法全局安装Browserify(或其他任何工具)。 I'm able to install things non-globally without issue. 我能够非全局地安装东西,而不会出现问题。

background: I'm running CentOS 6.6 on a corporate network behind a proxy. 背景:我正在代理后面的公司网络上运行CentOS 6.6。 I installed Node.js using "yum" as root. 我使用“ yum”作为根安装了Node.js。

$ sudo yum -y install nodejs

and npm (which wasn't installed with nodejs for some reason): 和npm(由于某种原因未与nodejs一起安装):

$ sudo yum -y install nodejs npm

This installed Node.js and NPM to the directories: 这将Node.js和NPM安装到目录中:

$ which node
/usr/bin/node

$ which npm
/usr/bin/npm

and put the "node_modules" under /usr/lib/node_modules. 并将“ node_modules”放在/ 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. 就像我说的那样,我在代理后面,所以我将“代理”和“ https-代理”配置属性设置为正确的值。

When I tried to install browserify (as specified on their site ) 当我尝试安装browserify(在其网站上指定)时

$ 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: 因此,我“阻塞”了/ usr / lib / node_modules目录,以使我可以访问node_modules中的mkdirs:

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

The error: Now when I try to install browserify globally I get a different error: 错误:现在,当我尝试全局安装browserify时,出现了另一个错误:

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? 我需要更改某些特殊内容以允许NPM创建符号链接吗?

Also, I tried running the install as root but it just sits there until eventually timing out: 另外,我尝试以root用户身份运行安装程序,但是它一直坐在那里直到最终超时:

...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). 全局模块应作为root(sudo)安装。 Where my process was failing (similar to yours) was the timeout when running this as root. 我的进程失败的地方(与您的失败类似)是以root用户身份运行时超时。 This was due to the fact the NPM was using the "git" protocol. 这是由于NPM使用了“ git”协议。 To get the packages to install, I had to run the following to my git config. 要安装软件包,我必须在git config中运行以下命令。

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

This solved my problem. 这解决了我的问题。

I was finally able to install modules globally using npm. 我终于可以使用npm在全球范围内安装模块。

What I did: 我做了什么:

I had to use sudo and set the proxy/https proxy in several places. 我不得不使用sudo并在几个地方设置了proxy / https代理。 I followed the advice from this blog: http://wil.boayue.com/blog/2013/06/14/using-npm-behind-a-proxy/ . 我遵循了该博客的建议: http : //wil.boayue.com/blog/2013/06/14/using-npm-behind-a-proxy/

I set the following variables in ~/.bashrc and exported them: 我在〜/ .bashrc中设置以下变量并将其导出:

  • http_proxy http_proxy
  • https_proxy https_proxy
  • npm_config_proxy npm_config_proxy
  • npm_config_https_proxy npm_config_https_proxy

I also added them to env_keep using visudo (so they'd be available to sudo). 我还使用visudo将它们添加到env_keep(因此它们可用于sudo)。

I then set the proxy and https-proxy config settings on npm using: 然后,我使用以下命令在npm上设置代理和https-proxy配置设置:

$ 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). 另外,有一点我意识到我的代理服务器不正确,不得不在几个地方进行更改(因此请务必仔细检查)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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