node.js 尝试安装任何模块时“无法从注册表中获取消息”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12913141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"message failed to fetch from registry" while trying to install any module
提问by Dexter
I can't install any node module from the npm.
我无法从 npm 安装任何节点模块。
npm install socket.io
The above command resulted to below output, it is not able to install socket.io
上述命令导致以下输出,无法安装socket.io
npm http GET https://registry.npmjs.org/socket.io
npm ERR! Error: failed to fetch from registry: socket.io
npm ERR! at /opt/node0610/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:139:12
npm ERR! at cb (/opt/node0610/lib/node_modules/npm/lib/utils/npm-registry-client/request.js:32:9)
npm ERR! at Request._callback (/opt/node0610/lib/node_modules/npm/lib/utils/npm-registry-client/request.js:137:18)
npm ERR! at Request.callback (/opt/node0610/lib/node_modules/npm/node_modules/request/main.js:109:22)
npm ERR! at Request.<anonymous> (/opt/node0610/lib/node_modules/npm/node_modules/request/main.js:198:58)
npm ERR! at Request.emit (events.js:88:20)
npm ERR! at ClientRequest.<anonymous> (/opt/node0610/lib/node_modules/npm/node_modules/request/main.js:195:10)
npm ERR! at ClientRequest.emit (events.js:67:17)
npm ERR! at CleartextStream.<anonymous> (http.js:1134:11)
npm ERR! at CleartextStream.emit (events.js:67:17)
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR!
npm ERR! System Linux 2.6.18-194.el5
npm ERR! command "node" "/opt/node0610/bin/npm" "install" "socket.io"
npm ERR! cwd /opt/node0610/lib/node_modules
npm ERR! node -v v0.6.10
npm ERR! npm -v 1.1.0-3
npm ERR! message failed to fetch from registry: socket.io
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /opt/node0610/lib/node_modules/npm-debug.log
npm not ok
My NPM Version is :
我的 NPM 版本是:
[applmgr@dev node_modules]$ npm --version
1.1.0-3
My NodeJS Version is :
我的 NodeJS 版本是:
[applmgr@dev node_modules]$ node --version
v0.6.10
回答by John Carter
I had this issue with npm v1.1.4(and node v0.6.12), which are the Ubuntu 12.04repository versions.
我在npm v1.1.4(和node v0.6.12)上遇到了这个问题,它们是Ubuntu 12.04存储库版本。
It looks like that version of npmisn't supported any more, updating node (and npm with it) resolved the issue.
似乎npm不再支持该版本,更新节点(以及带有它的 npm)解决了该问题。
First, uninstall the outdated version (optional, but I think this fixed an issue I was having with global modules not being pathed in).
首先,卸载过时的版本(可选,但我认为这解决了我遇到的全局模块未被路径化的问题)。
sudo apt-get purge nodejs npm
Then enable nodesource's repo and install:
然后启用 nodesource 的 repo 并安装:
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
Note - the previous advice was to use Chris Lea's repo, he's now migrated that to nodesource, see:
注意 - 之前的建议是使用 Chris Lea 的 repo,他现在将其迁移到 nodesource,请参阅:
- https://chrislea.com/2014/07/09/joining-forces-nodesource/
- https://nodesource.com/blog/chris-lea-joins-forces-with-nodesource
- https://chrislea.com/2014/07/09/joining-forces-nodesource/
- https://nodesource.com/blog/chris-lea-joins-forces-with-nodesource
From: here
来自:这里
回答by Dexter
https://github.com/isaacs/npm/issues/2119
https://github.com/isaacs/npm/issues/2119
I had to execute the command below:
我必须执行以下命令:
npm config set registry http://registry.npmjs.org/
However, that will make npminstall packages over an insecure HTTP connection. If you can, you should stick with
但是,这将使npm安装包通过不安全的 HTTP 连接。如果可以,你应该坚持
npm config set registry https://registry.npmjs.org/
instead to install over HTTPS.
而是通过 HTTPS 安装。
回答by geon
I'm on Ubuntu. I used apt-get to install node. Npm was not included in that package, so it had to be installed separately. I assumed that would work, but apparently the npm version in the Ubuntu distribution was outdated.
我在 Ubuntu 上。我使用 apt-get 安装节点。Npm 未包含在该软件包中,因此必须单独安装。我认为这会起作用,但显然 Ubuntu 发行版中的 npm 版本已经过时了。
The node wikihas this instruction:
节点维基有这个指令:
Obtaining a recent version of Node or installing on older Ubuntu and other apt-based distributions may require a few extra steps. Example install:
获取最新版本的 Node 或安装在较旧的 Ubuntu 和其他基于 apt 的发行版上可能需要一些额外的步骤。安装示例:
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
After that, npm was already included and worked perfectly.
在那之后,npm 已经包含在内并且完美运行。
回答by Katie
For me, it's usually a proxy issue, and I try everything:
对我来说,这通常是代理问题,我尝试了一切:
npm config set registry http://registry.npmjs.org/
npm config set strict-ssl false
npm config set proxy http://myusername:[email protected]:8080
npm config set https-proxy http://myusername:[email protected]:8080
set HTTPS_PROXY=http://myusername:[email protected]:8080
set HTTP_PROXY=http://myusername:[email protected]:8080
export HTTPS_PROXY=http://myusername:[email protected]:8080
export HTTP_PROXY=http://myusername:[email protected]:8080
export http_proxy=http://myusername:[email protected]:8080
npm --proxy http://myusername:[email protected]:8080 \
--without-ssl --insecure -g install
回答by Tushar
You also need to install software-properties-common for add-apt-repository to work. so it will be
您还需要安装 software-properties-common 才能使用 add-apt-repository。所以它会
sudo apt-get purge nodejs npm
sudo apt-get install -y python-software-properties python g++ make software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
回答by Edward Tan
One thing that has worked for me with random npm install errors (where the package that errors out is different under different times (but same environment) is to use this:
对我有用的一件事是随机 npm install 错误(其中错误的包在不同时间(但相同的环境)下不同)是使用这个:
npm cache clean
npm cache clean
And then repeat the process. Then the process seems to go smoother and the real problem and error message will emerge, where you can fix it and then proceed.
然后重复这个过程。然后这个过程似乎变得更顺利,真正的问题和错误信息就会出现,你可以在那里修复它然后继续。
This is based on experience of running npm install of a whole bunch of packages under a pretty bare Ubuntu installation inside a Docker instance. Sometimes there are build/make tools missing from the Ubuntu and the npm errors will not show the real problem until you clean the cache for some reason.
这是基于在 Docker 实例中的裸露 Ubuntu 安装下运行 npm install 一大堆软件包的经验。有时 Ubuntu 中缺少构建/制作工具,并且 npm 错误不会显示真正的问题,除非您出于某种原因清理缓存。
回答by Venar303
This problem is due to the https protocol, which is why the other solution works (by switching to the non-secure protocol).
这个问题是由 https 协议引起的,这就是为什么其他解决方案有效(通过切换到非安全协议)。
For me, the best solution was to compile the latest version of node, which includes npm
对我来说,最好的解决方案是编译最新版本的 node,其中包括 npm
apt-get purge nodejs npm
git clone https://github.com/nodejs/node ~/local/node
cd ~/local/node
./configure
make
make install
回答by Brian Low
There are now official instructions from joyent(primary nodejs backer). For Ubuntu:
现在有来自Joyent(主要 nodejs 支持者)的官方说明。对于 Ubuntu:
sudo apt-get purge nodejs npm
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
For other unix distributions, osx and windows see the link. Note this will install both node and npm.
对于其他 unix 发行版、osx 和 windows,请参阅链接。请注意,这将同时安装 node 和 npm。
回答by radtek
The only thing that worked for me on Elementary OS Luna, a Ubuntu Fork. I am on x86 architecture. I tried all the answers here but finally decided to install it from source.
在 Elementary OS Luna(Ubuntu Fork)上唯一对我有用的东西。我在 x86 架构上。我在这里尝试了所有答案,但最终决定从源代码安装它。
First, make sure its not installed using the package manager:
首先,确保它没有使用包管理器安装:
sudo apt-get purge nodejs npm -y
I went to the download page to lookup the latest source & download it, http://nodejs.org/download/. You can use curl, wget or your browser to get it:
我去下载页面查找最新源并下载它,http://nodejs.org/download/。您可以使用 curl、wget 或您的浏览器来获取它:
wget http://nodejs.org/dist/v0.10.34/node-v0.10.34.tar.gz
tar -xvf node-v0.10.34.tar.gz
cd node-v0.10.34
./configure
make
sudo make install
The make might take a while. When done, you should have node and npm installed and working in your /usr/local/bin directory which should be already on your path. You should verify where it lives:
制作可能需要一段时间。完成后,您应该已经安装了 node 和 npm 并在您的 /usr/local/bin 目录中工作,该目录应该已经在您的路径上。您应该验证它的位置:
which npm node
I also had to change the permissions to get it to work:
我还必须更改权限才能使其正常工作:
sudo chown -R $USER /usr/local
If it didn't work check your path:
如果它不起作用,请检查您的路径:
echo $PATH
Note that installing it this way, it will not be managed by apt-get package manager. Cheers!
请注意,以这种方式安装它,它不会由 apt-get 包管理器管理。干杯!
回答by Micha? Miszczyszyn
Recently I had this problem after upgrading node.js (and inevitably npm) to the newest version:
最近我在将 node.js(以及不可避免的 npm)升级到最新版本后遇到了这个问题:
> npm --version
< 2.0.0-alpha-5
> npm --version
< 2.0.0-alpha-5
Note: I didn't askfor an unstable version, I just got it after brew install npmon OSX.
注意:我没有要求不稳定的版本,我只是brew install npm在 OSX 上得到了它。
Downgrading npm fixed the problem for me.
降级 npm 为我解决了这个问题。
The easiest way to install the stable npm is npm install -g npmbut it might not work under some circumstances and downgrade of node.js might be needed then.
安装稳定的 npm 最简单的方法是,npm install -g npm但它在某些情况下可能不起作用,然后可能需要降级 node.js。

