解决npm 的 shasum check failed for错误

使用npm安装一些包失败,相似以下报错状况:html

 




网找到了一篇良心之做——npm install 无响应解决方案 (来自体验盒子),给出了3种解决方案,都可解决 npm install 慢、npm install 无响应、npm install 没法安装的问题。


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

方法一:使用cnpm,用淘宝 NPM 镜像

安装node

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

上面这种镜像使用方式将配置写死,下次用的时候配置还在。
附:搜索镜像: http://cnpmjs.orgjquery

安装模块 | $ cnpm install [name]
从 registry.npm.taobao.org 安装全部模块. 当安装的时候发现安装的模块尚未同步过来, 淘宝 NPM 会自动在后台进行同步, 而且会让你从官方 NPMregistry.npmjs.org 进行安装. 下次你再安装这个模块的时候, 就会直接从 淘宝 NPM 安装了.git

同步模块 | $ cnpm sync [moduleName]github

注意:cnpm支持 npm 除了 publish 以外的全部命令,也就是不支持publish,固然这并不影响咱们使用,publish时换回npm便可,这样也能解决npm install无响应的问题。sql

 

 

方法二:使用smart-npm,用淘宝NPM镜像

智能的 npm,让你在中国使用 npm 时,下载速度更快,使用更方便! 
因为用 npm 时,默认它会访问国外资源,因此会很是卡,有时甚至会被墙。 
smart-npm 能够在咱们使用 npm install 时自动从国内的镜像下载资源,而在咱们使用 npm publish 又能发布到官方的 registry 上。npm

安装测试

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

若是 window 用户安装最新版本不成功的话,能够试试安装 smart-npm@1。这样作的缘由是,npm 的升级使得在 mac 上没法经过 bin 别名的方式覆盖原来的 npm, 只能经过先删除原来的 npm link 文件,再建立一个新的,但这种方式在 window 上可能会有问题。 因此,若是你是 window 用户,而且经过上面脚本没法安装成功的话,能够用下面脚本再试试。ui

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

安装成功后默认会在你的 npm 用户配置文件 ~/.npmrc 中添加淘宝的 registry。this

卸载

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...

相关文章
相关标签/搜索