npm install xxx 出现Unexpected token < in

今日鸡汤:付出是必须的,不劳而获那是疯子的想法

问题场景

// 安装xlsx依赖
npm install --save  xlsx@0.14.1
Active code page: 65001
npm ERR! Unexpected token < in JSON at position 0 while parsing near '<!DOCTYPE html><html...'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\MySelf\AppData\Roaming\npm-cache\_logs\2022-10-05T09_56_47_541Z-debug.log

解决方案

// 设置仓库地址为官方地址,后续 npm install --save xxx将直接访问官网地址
npm config set registry https://registry.npmjs.org

原理

代理问题,有些项目install需要设置仓库为国内镜像加速地址,故而使用了代理地址

例:npm install --registry=https://registry.npm.taobao.org

在安装新的依赖无法安装时,临时切换为npm官网地址,后续再切换回去即可

作者有话

创作不易,如对你有帮助,望点赞收藏,有问题可评论区一起探讨!
作者持续分享NodeJs、Java、Python技术栈相关领域技能点,欢迎关注!

猜你喜欢

转载自blog.csdn.net/qq_45903258/article/details/127175027