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

nuxt官网:Installation · Get Started with Nuxt

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

swift 复制代码
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中:

bash 复制代码
# 将 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

打开终端,执行命令:

bash 复制代码
sudo vi /etc/hosts

然后添加内容如下:

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

复制代码
sudo killall -HUP mDNSResponder

windows修改host

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

bash 复制代码
# 将 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通了:

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

相关推荐
|晴 天|2 小时前
Vue 3 + TypeScript + Element Plus 博客系统开发总结与思考
前端·vue.js·typescript
猫3283 小时前
v-cloak
前端·javascript·vue.js
旷世奇才李先生3 小时前
Vue 3\+Vite\+Pinia实战:企业级前端项目架构设计
前端·javascript·vue.js
SoaringHeart4 小时前
Flutter进阶:用OverlayEntry 实现所有弹窗效果
前端·flutter
IT_陈寒6 小时前
Vite静态资源加载把我坑惨了
前端·人工智能·后端
herinspace6 小时前
管家婆实用贴-如何分离和附加数据库
开发语言·前端·javascript·数据库·语音识别
小码哥_常7 小时前
从MVC到MVI:一文吃透架构模式进化史
前端
嗷o嗷o7 小时前
Android BLE 的 notify 和 indicate 到底有什么区别
前端
豹哥学前端7 小时前
别再背“var 提升,let/const 不提升”了:揭开暂时性死区的真实面目
前端·面试
lar_slw7 小时前
k8s部署前端项目
前端·容器·kubernetes