尝试安装任何模块时“消息无法从注册表中获取”

本文解决了一个关于npm无法安装socket.io模块的问题,探讨了可能的原因,如npm注册表问题、网络连接、版本过时等,并提供了升级node和npm、更改npm注册表地址及Ubuntu环境下具体操作的解决方案。

本文翻译自:“message failed to fetch from registry” while trying to install any module

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!     <npm-@googlegroups.com>
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

#1楼

参考:https://stackoom.com/question/sBIT/尝试安装任何模块时-消息无法从注册表中获取


#2楼

It could be that the npm registry was down at the time or your connection dropped. 可能是当时npm注册表已关闭或您的连接断开。

Either way you should upgrade node and npm. 无论哪种方式,您都应该升级node和npm。

I would recommend using nave to manage your node environments. 我建议使用nave来管理您的节点环境。

https://npmjs.org/package/nave https://npmjs.org/package/nave

It allows you to easily install versions and quickly jump between them. 它允许您轻松安装版本并在它们之间快速跳转。


#3楼

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 npm install packages over an insecure HTTP connection. 但是,这会使npm安装包通过不安全的HTTP连接。 If you can, you should stick with 如果可以的话,你应该坚持下去

npm config set registry https://registry.npmjs.org/

instead to install over HTTPS. 而是通过HTTPS安装。


#4楼

I had this issue with npm v1.1.4 (and node v0.6.12 ), which are the Ubuntu 12.04 repository versions. 我在npm v1.1.4 (和node v0.6.12 )中遇到了这个问题,这是Ubuntu 12.04存储库版本。

It looks like that version of npm isn'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,请参阅:

From: here 来自: 这里


#5楼

The below method worked for me, Kudos to github user : midnightcodr 下面的方法对我有用,Kudos给github用户:midnightcodr

Make sure You remove any nodejs/npm packages already installed. 确保删除已安装的任何nodejs / npm软件包。

sudo apt-get purge nodejs

sudo apt-get purge npm

Now Install Node js using the command below( Thanks to midnightcodr on github) 现在使用下面的命令安装Node js(感谢github上的midnightcodr)

curl -L https://raw.github.com/midnightcodr/rpi_node_install/master/setup.sh | bash -s 0.10.24

Note that you can invoke node with command node and not nodejs. 请注意,您可以使用命令节点而不是nodejs来调用节点。

Once node is installed , Install npm 安装节点后,安装npm

sudo apt-get install npm

#6楼

I'm on Ubuntu. 我在Ubuntu上。 I used apt-get to install node. 我使用apt-get来安装节点。 Npm was not included in that package, so it had to be installed separately. Npm不包含在该软件包中,因此必须单独安装。 I assumed that would work, but apparently the npm version in the Ubuntu distribution was outdated. 我认为这样可行,但显然Ubuntu发行版中的npm版本已经过时了。

The node wiki has this instruction: 节点wiki有这个指令:

Obtaining a recent version of Node or installing on older Ubuntu and other apt-based distributions may require a few extra steps. 获取最新版本的Node或在较旧的Ubuntu和其他基于apt的发行版上安装可能需要一些额外的步骤。 Example install: 安装示例:

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已经被包括在内并且工作得很好。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值