惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
WordPress大学
WordPress大学
月光博客
月光博客
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - 司徒正美
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
Blog — PlanetScale
Blog — PlanetScale
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
L
LangChain Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
量子位

又见苍岚

COLMAP PatchMatch Stereo 算法详解 事件驱动的状态机框架:从理论到工程实践 Git 在国内网络环境下无法 Push 的排查与修复 —— 配置 Clash 代理 分段五次多项式插值原理详解 路径插值方法深度对比研究 Claude Code 使用指南 OpenClaw 记忆管理与技能创建指南 CBS(Conflict-Based Search)算法详解 A* 算法及其变种详解 OpenClaw 配置多 Agents Windows Powershell 无法加载文件,因为在此系统上禁止运行脚本问题的解决方案 MaxClaw 安装流程 大模型 AI 名词介绍 AList 网盘聚合工具简介 Protobuf 简介与测试 Claude Code 简介以及 GLM 4.7 模型接入 Github 歌词下载工具 163MusicLyrics Python __getattr__ 懒加载 Python TypedDict 机器人仿真平台 Gazebo 安装记录 机器人仿真平台 Gazebo 简介 多机器人路径规划问题(Multi-Agent Path Finding, MAPF)简介 Python exifread 读取修改过的 jpeg 信息错误问题修复 3D 坐标系变换的理解 3D 旋转矩阵基本概念 MongoDB Compass 介绍 Python 环境管理工具 uv Flutter 开发指南 Snipaste 安装下载与黑屏问题解决方案 全局路径规划算法记录
解决 npm install 报错 connect ECONNREFUSED 问题
Yiwei Zhang · 2023-04-11 · via 又见苍岚

使用 npm install 安装包一直报错 errno ECONNREFUSED,本文记录解决方案。

问题复现

在安装npm 任何包时都会报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$ npm install --save hexo-blog-encrypt
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ECONNREFUSED
npm ERR! syscall connect
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to https://registry.npmmirror.com/hexo-blog-encrypt failed, reason: connect ECONNREFUSED 127.0.0.1:31181
npm ERR! at ClientRequest.<anonymous> (E:\Program Files\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm ERR! at ClientRequest.emit (node:events:527:28)
npm ERR! at onerror (E:\Program Files\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:117:21)
npm ERR! at callbackError (E:\Program Files\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:136:17)
npm ERR! at processTicksAndRejections (node:internal/process/task_queues:96:5)
npm ERR! FetchError: request to https://registry.npmmirror.com/hexo-blog-encrypt failed, reason: connect ECONNREFUSED 127.0.0.1:31181
npm ERR! at ClientRequest.<anonymous> (E:\Program Files\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm ERR! at ClientRequest.emit (node:events:527:28)
npm ERR! at onerror (E:\Program Files\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:117:21)
npm ERR! at callbackError (E:\Program Files\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:136:17)
npm ERR! at processTicksAndRejections (node:internal/process/task_queues:96:5) {
npm ERR! code: 'ECONNREFUSED',
npm ERR! errno: 'ECONNREFUSED',
npm ERR! syscall: 'connect',
npm ERR! address: '127.0.0.1',
npm ERR! port: 31181,
npm ERR! type: 'system',
npm ERR! requiredBy: '.'
npm ERR! }
npm ERR!
npm ERR! If you are behind a proxy, please make sure that the
npm ERR! '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\2023-04-11T05_46_04_410Z-debug-0.log

核心错误信息:

1
reason: connect ECONNREFUSED 127.0.0.1:31181

问题原因

一般来说是翻墙工具或者加速器开启了网络代理,修改了相关配置导致 npm连接本机 31181 端口安装包。

确定这个问题可以查看 npm 的代理配置:

1
2
$ npm config get https-proxy
http://127.0.0.1:31181/

然后查看本地端口没有对应的服务开启 (Windows):

1
$ netstat -ano

此时基本可以确认就是代理导致的问题。

解决方案

清空相关代理,http-proxyproxy

1
2
npm config delete https-proxy
npm config delete proxy

查看配置代理结果

1
2
npm config get proxy
npm config get https-proxy

如果二者都返回 null 说明删除成功

此时修改镜像源才可能有用。

之后安装包就可以了

1
2
3
4
5
6
7
$ npm install --save hexo-blog-encrypt
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

added 1 package in 2s

1 package is looking for funding
run `npm fund` for details

参考资料

文章链接:
https://www.zywvvd.com/notes/coding/node-js/npm-install-error/npm-install-error/