【踩坑随笔】npm install 下载报错证书问题,换源没用

解决方案

npm install -g cnpm --registry=https://registry.npmmirror.com
cnpm install –save-dev electron

npm install 下载报错

npm error code ENOTFOUND
npm error syscall getaddrinfo
npm error errno ENOTFOUND
npm error network request to http://registry.cnpmjs.org/axios failed, reason: getaddrinfo ENOTFOUND registry.cnpmjs.org
npm error network This is a problem related to network connectivity.
npm error network In most cases you are behind a proxy or have bad network settings.
npm error network
npm error network If you are behind a proxy, please make sure that the
npm error network 'proxy' config is set properly.  See: 'npm help config'
npm error A complete log of this run can be found in: C:\Users\liron\AppData\Local\npm-cache\_logs\2025-02-28T10_05_22_174Z-debug-0.log
PS E:\Project\gitProject\weed_detection_project\frontend> npm config set registry https://registry.npmjs.org/
PS E:\Project\gitProject\weed_detection_project\frontend> npm install electron echarts axios
npm warn deprecated boolean@3.2.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm warn cleanup Failed to remove some directories [
npm warn cleanup       errno: -4048,
npm warn cleanup       code: 'EPERM',
npm warn cleanup       syscall: 'rmdir',
npm warn cleanup     }
npm warn cleanup   ]
npm warn cleanup ]
npm error command C:\Windows\system32\cmd.exe /d /s /c node install.js
npm error RequestError: unable to verify the first certificate
npm error     at ClientRequest.<anonymous> npm error     at Object.onceWrapper (node:events:633:26)
npm error     at ClientRequest.emit (node:events:530:35)
npm error     at origin.emit timer\dist\source\index.js:43:20)
npm error     at emitErrorEvent (node:_http_client:104:11)
npm error     at TLSSocket.socketErrorListener (node:_http_client:518:5)
npm error     at TLSSocket.emit (node:events:518:28)
npm error     at emitErrorNT (node:internal/streams/destroy:170:8)
npm error     at emitErrorCloseNT (node:internal/streams/destroy:129:3)
npm error     at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
npm error     at TLSSocket.onConnectSecure (node:_tls_wrap:1679:34)
npm error     at TLSSocket.emit (node:events:518:28)
npm error     at TLSSocket._finishInit (node:_tls_wrap:1078:8)
npm error     at ssl.onhandshakedone (node:_tls_wrap:864:12)
### 解决 npm install 报错方案 当遇到 `npm install` 报错时,保持冷静并依照特定的方法逐一排查可以有效解决问题[^1]。 #### 网络相关报错处理 对于因网络连接不稳定或代理设置不正确引发的错误,建议先尝试更换国内镜像源来加速下载速度以及提高稳定性。可以通过如下命令切换至淘宝镜像: ```bash npm config set registry https://registry.npmmirror.com/ ``` 如果仍然存在超时等问题,则考虑调整最大重试次数和时间间隔参数: ```bash npm set fetch-retry-mintimeout 20000 npm set fetch-retry-maxtimeout 120000 ``` #### 权限不足 (EPERM) 错误修复 针对权限不够导致的操作失败情况,比如出现类似 `errno: -4048`, `code: 'EPERM'`, `syscall: 'scandir'` 的提示信息时,这通常是由于文件夹访问权限受限所引起的[^2]。此时可采取以下措施之一进行修正: - 使用管理员身份运行终端工具; - 更改当前工作目录及其子项的所有权给当前用户,在 Unix/Linux/MacOS 下执行: ```bash sudo chown -R $USER ~/.npm ``` - 或者通过配置使 NPM 不再全局安装依赖包而是本地化管理,从而减少对系统级路径写入的需求: ```json { "save-exact": true, "global-style": false, "ignore-scripts": false, "legacy-peer-deps": true } ``` 以上策略有助于克服大多数常见的 `npm install` 过程中的障碍。当然还有其他类型的异常状况等待探索与应对,但遵循上述指导原则往往能帮助开发者顺利度过难关。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

RIKI_1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值