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