解决npm ERR! Unexpected end of JSON input while parsing near...的方法

解决npm ERR! Unexpected end of JSON input while parsing near...的方法

今天在创建项目的时候,发现一直创建不成功,安装项目依赖的时候报错:npm ERR! Unexpected end of JSON input while parsing near…

具体报错详情:
在这里插入图片描述经过自己亲测发现如下解决方法:
方案一(亲测已解决):

  1. 清除缓存
npm cache clean --force
  1. 再安装
npm install

方案二(亲测):
第一次按照上面的方法 npm cache clean --force 轻松就解决问题了,但是今天我用的时候发现依然报错:

npm ERR! Unexpected end of JSON input while parsing near...
......
npm ERR! A complete log of this run can be found in:
......

于是我就按着上次的方法发现不行,还是报错,我就又连着试了好几次还是不行
后来查阅各种方案,发现只需要把镜像改一下就行了,具体看下面

  1. 第一步还是:npm cache clean --force
npm cache clean --force
  1. 第二步:切换为淘宝镜像
npm config set registry https://registry.npm.taobao.org/
npm config get registry https://registry.npm.taobao.org/

验证时候切换淘宝镜像成功,命令行输入: npm config list
在这里插入图片描述

3.第三步:

npm install

本文引自

https://blog.csdn.net/zsl15039718107/article/details/104128166/

原文地址:https://www.cnblogs.com/coderD/p/14153730.html