首页 前端知识 npm或者pnpm或者yarn安装依赖报错ENOTFOUND解决办法

npm或者pnpm或者yarn安装依赖报错ENOTFOUND解决办法

2024-04-30 12:04:26 前端知识 前端哥 651 111 我要收藏

如果报错说安装依赖报错,大概率是因为npm源没有设置对,比如我这里安装protobufjs的时候报错:ENOTFOUND

npm ERR! code ENOTFOUND
npm ERR! syscall getaddrinfo
npm ERR! errno ENOTFOUND
npm ERR! network request to https://registry.cnpmjs.org/protobufjs-cli failed, reason: getaddrinfo ENOTFOUND registry.cnpmjs.org
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2024-01-23T03_22_49_241Z-debug-0.log
PS C:\Users\Administrator> npm i protobufjs-cli
npm ERR! code ENOTFOUND
npm ERR! syscall getaddrinfo
npm ERR! errno ENOTFOUND
npm ERR! network request to https://registry.cnpmjs.org/protobufjs-cli failed, reason: getaddrinfo ENOTFOUND registry.cnpmjs.org
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2024-01-23T03_24_27_021Z-debug-0.log

我刚开始也怀疑是网络问题,但是发现把代理关了也还是不行,然后查看npm源里面是否存在这个依赖包,发现npm官方的源里面是有这个依赖的:protobufjs-cli - npm 

查看一下自己的源地址:

npm config get registry

发现是淘宝的源地址:https://registry.npm.taobao.org

然后我就把源地址改为了官方源: 

npm config set registry https://registry.npmjs.org/

最后再试一下就好了:

转载请注明出处或者链接地址:https://www.qianduange.cn//article/6755.html
标签
评论
会员中心 联系我 留言建议 回顶部
复制成功!