$ npm install express --save
npm http GET https://registry.npmjs.org/express

npm ERR! Error: failed to fetch from registry: express  
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" "express"  
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: express  
npm ERR!  
npm ERR! Additional logging details can be found in:  
npm ERR!     /opt/node0610/lib/node_modules/npm-debug.log  
npm not ok  

As I have found out in the past, there are quite a few reasons why you might get the “failed to fetch from registry” error, so here are a few ways to fix it.

Old/Buggy NPM Version

As you might have noticed from the error message above, the npm version being used is pretty old. In this example we were using Node v0.6.10 and npm v1.1.0-3. This version is known to have some problems with Ubuntu 12.04, so your best bet is to update Node (and npm along with it) to the newest version:

$ sudo npm update npm -g

If you want to re-install completely, you’ll first want to completely remove the current Node/npm executables:

$ sudo apt-get purge nodejs npm

Then re-install using a more updated version, like from Nodesource:

$ curl -sL https://deb.nodesource.com/setup | sudo bash -
$ sudo apt-get install -y nodejs

Or, even better, you can check out this article for a more thorough guide to installing Node.js on Ubuntu.

Can’t Download Over HTTPS

For one reason or another, some people can’t connect to the registry via HTTPS. This can be fixed by setting the registry to use HTTP instead:

$ npm config set registry http://registry.npmjs.org/
$ npm config set strict-ssl false

This isn’t recommended, however, since your packages will then be downloaded insecurely. It would be best to find the actual root cause instead of using a work-around like this.

Corporate Proxy

For many people, the root cause is actually because a proxy is being used on their network. If this is the case, you can use the following commands to set the HTTP and HTTPS proxies:

$ npm config set proxy http://user:password@proxy.example.com:8181
$ npm config set https-proxy http://user:password@proxy.example.com:8181

This will save the new configurations and should allow you to access the internet with npm.

                </div>
                <footer class="post-footer clearfix">
                    <div class="pull-left tag-list">
                        <i class="fa fa-folder-open-o"></i>
                        <a href="/tag/npm/">npm</a>,<a href="/tag/node/">node</a>
                    </div>
                    <div class="pull-right share">
                        <div>
<ul class="share-icons">
    <!-- twitter -->
    <li>
        <a href="https://twitter.com/share?text=NPM%20Error%20%22failed%20to%20fetch%20from%20registry%22%20when%20Installing%20Module&amp;url=http://stackabuse.com/npm-error-failed-to-fetch-from-registry-when-installing-module/" onclick="window.open(this.href, 'twitter-share', 'width=550,height=235');return false;"><i class="fa fa-twitter" style="color:#55acee;"></i></a>
    </li>
    <!-- facebook -->
    <li>
        <a href="https://www.facebook.com/sharer/sharer.php?u=http://stackabuse.com/npm-error-failed-to-fetch-from-registry-when-installing-module/" onclick="window.open(this.href, 'facebook-share','width=580,height=296');return false;"><i class="fa fa-facebook" style="color:#3b5998;"></i></a>
    </li>
    <!-- google plus -->
    <li>
        <a href="https://plus.google.com/share?url=http://stackabuse.com/npm-error-failed-to-fetch-from-registry-when-installing-module/" onclick="window.open(this.href, 'google-plus-share', 'width=490,height=530');return false;"><i class="fa fa-google-plus" style="color:#dc4e41;"></i></a>
    </li>
    <!-- linkedin -->
    <li>
        <a href="https://www.linkedin.com/shareArticle?mini=true%26url=http://stackabuse.com/npm-error-failed-to-fetch-from-registry-when-installing-module/%26source=http://stackabuse.com" onclick="window.open(this.href, 'linkedin-share', 'width=490,height=530');return false;"><i class="fa fa-linkedin" style="color:#0077b5;"></i></a>
    </li>
</ul>
分类: Experience

头像

小贱贱要飞

理想不只是成为一名程序猿,是成为一名编写人们生活每一步的艺术家!

0 条评论

发表评论

电子邮件地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据