Ubuntu系统下npm安装bootstrap添加到package.json失败如何解决
问题根因
你遇到的Unexpected end of JSON input报错属于npm本地缓存损坏类问题,之前拉取的bootstrap包元数据缓存文件不完整,JSON解析失败导致安装终止。
修复步骤
- 强制清空npm本地缓存
npm cache clean --force
- 验证缓存清理结果(非必须,可跳过)
npm cache verify
- 重新执行bootstrap安装命令
npm install bootstrap --save
- 若上述操作后仍出现同类错误,可升级npm到最新稳定版后重试
npm install -g npm@latest
可选优化(针对源访问不稳定的情况)
如果是网络波动导致的缓存损坏,可临时指定国内镜像源执行安装:
npm install bootstrap --save --registry=https://registry.npmmirror.com
如果需要长期切换npm源为国内镜像,执行以下命令:
npm config set registry https://registry.npmmirror.com
内容的提问来源于stack exchange,提问作者Reynaldo Castante
相关产品推荐
相关产品推荐

