NPM Error “failed to fetch from registry” when Installing Module

    $ npm install express --save
    npm http GET
    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!     <>  
    npm ERR! or email it to:  
    npm ERR!     <>  
    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 | 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
    $ 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
    $ npm config set https-proxy

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

                    <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 class="pull-right share">
    <ul class="share-icons">
        <!-- twitter -->
            <a href=";url=" onclick=", 'twitter-share', 'width=550,height=235');return false;"><i class="fa fa-twitter" style="color:#55acee;"></i></a>
        <!-- facebook -->
            <a href="" onclick=", 'facebook-share','width=580,height=296');return false;"><i class="fa fa-facebook" style="color:#3b5998;"></i></a>
        <!-- google plus -->
            <a href="" onclick=", 'google-plus-share', 'width=490,height=530');return false;"><i class="fa fa-google-plus" style="color:#dc4e41;"></i></a>
        <!-- linkedin -->
            <a href="" onclick=", 'linkedin-share', 'width=490,height=530');return false;"><i class="fa fa-linkedin" style="color:#0077b5;"></i></a>
复制或转载请以超链接形式注明转自Who am I ?,原文地址《NPM Error “failed to fetch from registry” when Installing Module
喜欢 | 0