坑1
当在npm install 的时候遇到如下ERR。
npm ERR! Unexpected end of JSON input while parsing near ’
解决方法:
npm cache clean --force
坑2
当npm使用淘宝镜像之后,发现npm search 发生错误。
解决方法:
从淘宝进行换用官方镜像后再执行npm search
官方
npm config set registry "https://registry.npmjs.org"
淘宝
npm config set registry "https://registry.npm.taobao.org"
坑3
当遇到如下错误的时候,果断切换到淘宝镜像,然后在重新执行。
npm ERR! network request to https://registry.npmjs.org/react-scripts failed
解决方法:
淘宝
npm config set registry "https://registry.npm.taobao.org"
坑4
遇到npx create-react-app app特别的慢,可能是因为网络服务不行。
解决方法:
##安装进行地址注册管理包nrm
$ npm install -g nrm
##查看已有进行地址list
$ nrm ls
* npm ----- https://registry.npmjs.org/
cnpm ---- http://r.cnpmjs.org/
taobao -- https://registry.npm.taobao.org/
nj ------ https://registry.nodejitsu.com/
skimdb -- https://skimdb.npmjs.com/registry
##测试镜像地址网络速度
$ nrm test cnpm
cnpm --- 335ms
##选择一个好用的,切换使用
$ nrm use cnpm //switch registry to cnpm
Registry has been set to: http://r.cnpmjs.org/
抗5
在遇到npm卡死或者出错的时候,网上有很多文章给出的建议是删除C:\Users\<username>\.nrmrc
文件,然后删除此文件之后,在执行npm时候发现各种慢卡问题出现。
C:\Users\<username>\.nrmrc
这个文件是npm的自定义配置存储文件,当执行npm config set registry "url"
后就会生成,如果删除了则恢复默认。
如果小伙伴有人通过npm config set
修改了npm的一些路径呢???!!!对头,重新下载各种依赖文件。
解决方法:
修改%NODEJS_HOME%\node_modules\npm\npmrc
文件。
prefix=D:\Development\nodejs\appdata\npm
cache=D:\Development\nodejs\appdata\npm-cache
tmp=D:\Development\nodejs\appdata\npm-tmp
userconfig=D:\Development\nodejs\appdata\.npmrc
删除C:\Users\<username>\.nrmrc
后,重新创建环境即可。
坑6
安装包的时候遇到如下情况.
情况1
npm ERR! code Z_BUF_ERROR
npm ERR! errno -5
npm ERR! zlib: unexpected end of file
npm ERR! A complete log of this run can be found in:
npm ERR! ... ...\_logs\2019-05-19T12_13_08_875Z-debug.log
情况2
npm ERR! Unexpected end of JSON input while parsing near '.../core":"7.0.0-beta.48'
解决方法:
尝试使用npm cache clean --force
命令后,重新开始。
npm cache clean --force
npm WARN using --force I sure hope you know what you are doing.