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

最后再试一下就好了:

// 用于在项目中引入
npm i protobufjs


// 用于编译proto文件
npm i protobufjs-cli

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐