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

发布时间:2024年01月23日

如果报错说安装依赖报错,大概率是因为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://blog.csdn.net/weixin_44786530/article/details/135767569
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。