当前位置 : 主页 > 编程语言 > 其它开发 >

npm ERR! code ETIMEDOUT npm ERR! syscall connect npm ERR! errno ETIMEDOUT npm ERR! network reques...

来源:互联网 收集:自由互联 发布时间:2022-06-07
npm 安装问题之 npm ERR! code ETIMEDOUT npm ERR! syscall connect npm ERR! errno ETIMEDOUT npm ERR! network reques... 一、前言(问题描述) 最近在安装 express 时,老是报错,我用了 npm 命令和 yarn 命令来安装都
npm 安装问题之 npm ERR! code ETIMEDOUT npm ERR! syscall connect npm ERR! errno ETIMEDOUT npm ERR! network reques... 一、前言(问题描述)

最近在安装 express 时,老是报错,我用了 npm 命令和 yarn 命令来安装都报错,两者的报错详细信息如下:

使用 npm 命令安装时:

npm ERR! code ETIMEDOUT
npm ERR! syscall connect
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npm.taobao.org/mkdirp failed, reason: connect ETIMEDOUT 61.160.228.203:443
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'

大概意思就是说 “网络 在大多数情况下,您使用代理服务器或网络设置错误。”

使用 yarn 命令安装时:

yarn add v1.22.18
info No lockfile found.
[1/4] Resolving packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.yarnpkg.com/express: connect ETIMEDOUT 104.16.20.35:443".
info If you think this is a bug, please open a bug report with the information provided in "D:\\Links\\Desktop\\ajax_study\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

大概意思就是说 “您的网络连接似乎有问题。 正在重试...”

在我们刚开始安装 npm 或 yarn 时,默认使用的代理服务器都是国外,所以在使用这两个命令安装包的时候就很容易出问题,令人烦恼,对此,我个人的解决方法如下(亲测有效)。


二、解决方法

最直接的方法就是将代理服务器更换为国内的代理服务器(淘宝镜像)

1、安装淘宝镜像

//前提条件是安装了 yarn,或者使用 npm
yarn config set registry https://registry.npm.taobao.org

 

2、清除原有的代理

yarn config delete proxy
npm config rm proxy
npm config rm https-proxy

 

3、安装 cnpm 镜像并作为代理

安装cnpm镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org
使用代理registry
npm config set registry https://registry.npm.taobao.org

 

4、使用命令查看是否更换了镜像

npm config list

三、测试结果
PS D:\Links\Desktop\ajax_study> npm i express

added 57 packages in 9s

PS D:\Links\Desktop\ajax_study>

 

上一篇:新人必备的 Linux 命令。。
下一篇:没有了
网友评论