解決npm 的 shasum check failed for錯誤


使用npm安裝一些包失敗,類似如下報錯情況:

 
 C:\Program Files\nodejs>npm update npm npm ERR! Windows_NT 10.0.14393 npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "update" "npm" npm ERR! node v6.2.0 npm ERR! npm v2.14.19 npm ERR! shasum check failed for C:\Users\kuaima\AppData\Local\Temp\npm-18136-7181dc7d\registry.npmjs.org\npm\-\npm-4.0.5.tgz npm ERR! Expected: a9c3c00c3c5bd6b0538c71109e019afd9d5b1403 npm ERR! Actual: 229ee9303b213d8ad584a6d4f65b971874d5b0e9 npm ERR! From: https://registry.npmjs.org/npm/-/npm-4.0.5.tgz npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! <https://github.com/npm/npm/issues> npm ERR! Please include the following file with any support request: npm ERR! C:\Program Files\nodejs\npm-debug.log



網找到了一篇良心之作——npm install 無響應解決方案 (來自體驗盒子),給出了3種解決方案,均可解決 npm install 慢、npm install 無響應、npm install 無法安裝的問題。


方法一:使用cnpm,用淘寶 NPM 鏡像

安裝

npm install cnpm -g --registry=https://registry.npm.taobao.org

上面這種鏡像使用方式將配置寫死,下次用的時候配置還在。
附:搜索鏡像: http://cnpmjs.org

安裝模塊 | $ cnpm install [name]
從 registry.npm.taobao.org 安裝所有模塊. 當安裝的時候發現安裝的模塊還沒有同步過來, 淘寶 NPM 會自動在后台進行同步, 並且會讓你從官方 NPMregistry.npmjs.org 進行安裝. 下次你再安裝這個模塊的時候, 就會直接從 淘寶 NPM 安裝了.

同步模塊 | $ cnpm sync [moduleName]

注意:cnpm支持 npm 除了 publish 之外的所有命令,也就是不支持publish,當然這並不影響我們使用,publish時換回npm即可,這樣也能解決npm install無響應的問題。

 

 

方法二:使用smart-npm,用淘寶NPM鏡像

智能的 npm,讓你在中國使用 npm 時,下載速度更快,使用更方便! 
由於用 npm 時,默認它會訪問國外資源,所以會非常卡,有時甚至會被牆。 
smart-npm 可以在我們使用 npm install 時自動從國內的鏡像下載資源,而在我們使用 npm publish 又能發布到官方的 registry 上。

安裝

npm install --global smart-npm --registry=https://registry.npm.taobao.org/

如果 window 用戶安裝最新版本不成功的話,可以試試安裝 smart-npm@1。這樣做的原因是,npm 的升級使得在 mac 上無法通過 bin 別名的方式覆蓋原來的 npm, 只能通過先刪除原來的 npm link 文件,再創建一個新的,但這種方式在 window 上可能會有問題。 所以,如果你是 window 用戶,並且通過上面腳本無法安裝成功的話,可以用下面腳本再試試。

npm install --global smart-npm@1 --registry=https://registry.npm.taobao.org/

安裝成功后默認會在你的 npm 用戶配置文件 ~/.npmrc 中添加淘寶的 registry。

卸載

npm smart uninstall # 2.x.x 版本的 smart-npm 在卸載前需要先執行此腳本 npm uninstall --global smart-npm

注意:如果直接執行 npm uninstall 會導致找不到 npm 文件

Mac 或 Linux 用戶可以使用下面命令恢復之前備份的 npm

mv $(which npm-original) $(dirname $(which npm-original))/npm

使用

  1. 安裝后系統的 npm 會被替換了,如果你要使用原生的 npm 命令,請用 npm-original 。

  2. 新的 npm 會自動根據你使用的命令切換 registry,當你使用 publish, config, adduser, star 等(click here to see more) 命令時,會強制使用官方的 registry https://registry.npmjs.org;當你使用其它命令時,都會使用淘寶的鏡像https://registry.npm.taobao.org/

  • 如果要強制使用官方的 registry, 只要在命令后面加上 --npm 即可。
    比如: npm install jquery --npm,就會使用官方的 registry 去拉取 jquery。(當鏡像沒有及時更新時,用此會選項很有效)

  • 如果要強制使用某個 registry 時,只要在命令后面添加 registry 參數即可。
    比如:npm install jquery --registry=https://r.cnpmjs.org,就會使用你指定的 registry 去拉取 jquery。

  • 如果你想修改默認的淘寶鏡像或者官方的 registry,可以在你的環境變量中添加這兩個參數:NPM_OFFICIAL_REGISTRY,NPM_MIRROR_REGISTRY,以此來修改默認的官方 registry 和 淘寶鏡像 registry。更多環境變量的配置請點擊這里

 

 

方法三:使用nrm

nrm允許你快速地在如下 NPM 源間切換,現已支持now include: npm, cnpm, taobao,nj(nodejitsu), rednpm。注意:nrm只是一個源管理器,也不能使用publish命令。

安裝

npm install -g nrm

示例

$ nrm ls npm ---- https://registry.npmjs.org/ cnpm --- http://r.cnpmjs.org/ * taobao - https://registry.npm.taobao.org/ nj ----- https://registry.nodejitsu.com/ rednpm - http://registry.mirror.cqupt.edu.cn/ npmMirror https://skimdb.npmjs.com/registry/ edunpm - http://registry.enpmjs.org/ $ nrm use cnpm //switch registry to cnpm Registry has been set to: http://r.cnpmjs.org/

使用

Usage: nrm [options] [command] Commands: ls List all the registries use Change registry to registry add [home] Add one custom registry del Delete one custom registry home [browser] Open the homepage of registry with optional browser test [registry] Show the response time for one or all registries help Print this help Options: -h, --help output usage information -V, --version output the version number 

增加源 | nrm add [home]
刪除源 | nrm del
測試速度 | nrm test

參考
http://www.uedbox.com/npm-ins... 
http://www.uedbox.com/ https://npm.taobao.org/ 
http://qiu8310.github.io/smar... 
http://qiu8310.github.io/smar...


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM