之前玩树莓派时,安装npm经常会遇到ERR。
root@raspberrypi:/home/pi# sudo npm install -g npm
npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning undefined: network timeout at: https://registry.npmjs.org/npm
npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation.
npm ERR! Unexpected end of JSON input while parsing near '...s-close","editor","np'
解决办法
- 清除代理
npm config set proxy null
npm config set https-proxy null
- 重置设置
npm config set registry http://registry.cnpmjs.org/
- 如果重置仍不行,可以设置为淘宝源
npm config set registry https://registry.npm.taobao.org