解决 npm install 时遇到的 Error installing vscode.d.ts: Error: getaddrinfo ENOEN...
source link: https://hellodk.cn/post/649
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
解决 npm install 时遇到的 Error installing vscode.d.ts: Error: getaddrinfo ENOENT raw.githubusercontent.com 问题
本次手动安装一个 vscode 扩展。在对应目录下执行 npm install
遇到错误,如下
Fetching vscode.d.ts from: https://raw.githubusercontent.com/Microsoft/vscode/809e7b30e928e0c430141b3e6abf1f63aaf55589/src/vs/vscode.d.ts
Error installing vscode.d.ts: Error: getaddrinfo ENOENT raw.githubusercontent.com
乍一看是网络问题。那就对终端设置一下代理吧。
注意:Windows 下不同终端设置临时代理的方法不一样。可以参考这篇文章。
我当前使用的是 cmd。设置前 curl 一下 google.com 看是怎样的
curl -v http://www.google.com
输出可能是下面这样的
curl -v http://www.google.com
* Rebuilt URL to: http://www.google.com/
* Trying 31.13.95.37...
* TCP_NODELAY set
* connect to 31.13.95.37 port 80 failed: Timed out
* Failed to connect to www.google.com port 80: Timed out
* Closing connection 0
curl: (7) Failed to connect to www.google.com port 80: Timed out
那么开始设置
set http_proxy=http://127.0.0.1:7890
set https_proxy=http://127.0.0.1:7890
设置后,再次 curl 查看curl的结果是不是变了呢
输出类似于这样的内容,说明本次代理有效
继续执行 npm install
,发现还是不行。
继续探索。注意到上面的url https://raw.githubusercontent.com/Microsoft/vscode/809e7b30e928e0c430141b3e6abf1f63aaf55589/src/vs/vscode.d.ts
通过浏览器访问,通过 127.0.0.1:7890 的 socks 代理访问成功。
切换成直接连接,就不成功。立马想到问题所在。
进入 wsl2 的 ubuntu 子系统,执行 dig raw.githubusercontent.com
查到这个 host 的ip 是 199.232.28.133
虽然 github.com 还没有被墙,但是 raw.githubusercontent.com
早已被墙了。
现在就更改一下 hosts 文件吧,windows下该文件位于 C:\Windows\System32\drivers\etc\hosts
通过管理员权限打开 notepad.exe
然后编辑这个文件,增加一行,内容为 199.232.28.133 raw.githubusercontent.com
然后保存。
接着再 npm install
经过一段时间的等待,成功了。
Fetching vscode.d.ts from: https://raw.githubusercontent.com/Microsoft/vscode/809e7b30e928e0c430141b3e6abf1f63aaf55589/src/vs/vscode.d.ts
vscode.d.ts successfully installed!
-
另外,本文在修改 hosts 文件之前,也尝试安装 npm 的淘宝镜像(如下),通过
cnpm install
也没有成功。因为最终都是要访问那个文件,必须要翻墙才行。npm install -g cnpm --registry=https://registry.npm.taobao.org
- 通过 http_proxy 和 https_proxy 不成功,有可能访问这个主机依然是直连导致的。我尝试过打开代理软件的全局代理模式,没有成功。另外通过本文说到的设置临时代理的方式,之所以说是临时的代理,因为把终端关掉就能使此代理在终端失效,新打开的终端是没有代理的能力的。如果想要配置全局的代理,可以配置全局的终端代理。
Recommend
-
8
vscode配置c++可能遇到的俩问题(头文件找不到和找不到编译的文件) ...
-
19
Lean Admin is a Laravel package for building custom admin panels. It's based on the TALLstack (Livewire & Alpine) and its main focus is customizability. Start by defining re...
-
7
getaddrinfo(2022) New Years’ Resolutions aren’t really my jam. Over the years, I usually idly ponder some vague notion (usually “get in better shape“) in late December, and mostly forge...
-
2
Some things about getaddrinfo that surprised me Hello! Here are some things you may or may not have noticed about DNS: when you resolve a DNS name in a Python program, it checks /etc/hosts
-
5
DNS 负载均衡方案的失效 通过 DNS 实现负载均衡是一种常见的方案。这种方案通常会返回多个 A 记录,客户端会按照 DNS 响应中的顺序依次尝试去连接服务器,直到成功为止。这个方案对于客户端是有要求的,即客户端必须严格按照 DNS 响应中的地址顺序来...
-
8
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again768 错误日志 [2022-05-12 16:53:01][error] [数据驾驶舱] 命令行任务异常,SQLSTATE[HY000] [2002] php_network_geta...
-
5
Node applications on App Service Linux and getaddrinfo ENOTFOUND 5 minute read | By Anthony Salemo ...
-
7
译|getaddrinfo with round robin DNS and happy eyeballs 这不是新闻。这只是一些事实,但似乎仍然有许多人不知道,所以我想帮助记录这些内容,以帮助教育世界。我首先会通过提供完整的背景信息来绕着主题转一转……
-
4
getaddrinfo() on glibc calls getenv(), oh boy There are more than a few bear traps in the larger Unix environment that continue to catch people off-guard. One of the perennial favorites is thread safety, particularly as it applies to...
-
3
解决pip install x ERROR: Could not install packages due to an OSError…问题 作者:
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK