nuxt安装报错Error: Failed to download template from registry: Failed download raw.githubusercontent.com

2,623 阅读1分钟

nuxt官网:Installation · Get Started with Nuxt 

我们通过执行如下命令,创建 Nuxt 项目时: 

npx nuxi@latest init <project-name>

报错:

song$ npx nuxi@latest init nuxt-demo 

[17:32:00]  ERROR  Error: Failed to download template from registry: Failed to download https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json: TypeError: fetch failed 

报错原因:这个问题应该是DNS解析不到raw.githubusercontent.com的IP,导致链接失败的

这个时候ping也ping不通:

修改host文件

查询一下raw.githubusercontent.com对应的ip地址是啥:“raw.githubusercontent.com”A记录/cname检测结果--Dns查询|dns查询--站长工具

查到之后:

把这些ip添加到host中:

# 将 Nuxt 下载请求的服务器域名与其服务器 IP 直接映射
185.199.108.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com

mac中修改host

打开终端,执行命令:

sudo vi /etc/hosts

然后添加内容如下: 

修改完之后要刷新hosts生效:

sudo killall -HUP mDNSResponder

windows修改host

复制自己电脑的 C:\Windows\System32\drivers\etc 目录下的 hosts 文件到桌面上,然后修改里面的内容,添加如下内容:

# 将 Nuxt 下载请求的服务器域名与其服务器 IP 直接映射
185.199.108.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com

然后将桌面上的文件移动到  C:\Windows\System32\drivers\etc 下面并覆盖原来的hosts文件,然后重新打开一个终端即可。

重新执行安装命令

这个时候其实ping一下就可以知道已经可以ping通了:

然后重新运行安装命令就可以了: