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

如果报错说安装依赖报错,大概率是因为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/

最后再试一下就好了:

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-24 12:18:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-24 12:18:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-24 12:18:02       82 阅读
  4. Python语言-面向对象

    2024-01-24 12:18:02       91 阅读

热门阅读

  1. 27.【TypeScript 教程】迭代器(Iterator)

    2024-01-24 12:18:02       56 阅读
  2. php正则电话号

    2024-01-24 12:18:02       56 阅读
  3. NLP自然语言介绍

    2024-01-24 12:18:02       57 阅读
  4. CSS的书写位置

    2024-01-24 12:18:02       63 阅读
  5. 编程笔记 html5&css&js 055 CSS颜色表

    2024-01-24 12:18:02       50 阅读
  6. 基于easyswoole开发的聊天室

    2024-01-24 12:18:02       48 阅读
  7. 【Docker】Docker学习⑥ - 网络部分

    2024-01-24 12:18:02       36 阅读
  8. leetcode-相交链表

    2024-01-24 12:18:02       57 阅读
  9. tomcat、mysql连接数配置

    2024-01-24 12:18:02       50 阅读
  10. 05-使用结构体构建相关数据

    2024-01-24 12:18:02       46 阅读