解决npm,pnpm,yarn等安装electron超时等问题

我在安装electron的时候,出现了超时等等各种问题:

(RequestError: connect ETIMEDOUT 20.205.243.166:443) 

npm yarn:Request Error: connect ETIMEDOUT 20.205.243.166:443

RequestError: socket hang up

npm ERR! Cannot read properties of null (reading 'matches')
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\caiqi2\AppData\Local\npm-cache\_logs\2023-07-04T11_54_

出现问题的原因

1.可能是你的网速不好,或者访问github.com速度慢

2.可能是你没有清理npm缓存

3.可能是你的node版本太高导致的

解决办法 

1.如果是你网速不好或者访问github.com超时等问题,可以通过修改hosts文件来解决,或者修改npm源来解决。

修改npm源:

npm config set registry https://registry.npm.taobao.org/

更改host文件:

找到\Windows\Systems32\divers\etc下面这个hosts文件,然后拷贝一份出来,修改拷贝后的文件里里面,添加一行:这一行的ip是从: 多个地点ping[https://github.com]服务器-网站测速-站长工具

这里获取的,看哪个速度快,就将ip考下来,然后贴进去,然后替换etc下面的那个hosts文件:

最后执行刷新host:然后重新安装试试。

ipconfig /flushdns

2.清除npm缓存,然后重新安装

删除node_modules,并执行命令:

npm cache clean --force

然后重新执行:

 npm install

3.切换node版本

使用nvm可以很方便的管理node版本,我这次遇到的问题就是因为node版本太高导致的,所以这里我降级到16.18.0就好了

猜你喜欢

转载自blog.csdn.net/weixin_44786530/article/details/135329398