nuxt初始化被墙究极解决方案

177 阅读1分钟

问题

在安装nuxt3的时候,经常遇到被墙的问题

Error: Failed to download template from registry: Failed to download https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json: TypeError: fetch failed

解决方案

第一步 通过域名获取ip

前往www.ipaddress.com/ip-lookup,输入raw.githubusercontent.com,解析出ipv4和ipv6的地址

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
2606:50c0:8000::154 raw.githubusercontent.com
2606:50c0:8001::154 raw.githubusercontent.com
2606:50c0:8002::154 raw.githubusercontent.com
2606:50c0:8003::154 raw.githubusercontent.com

C:\Windows\System32\drivers\etc\hosts追加

第二步 刷新本机DNS

ipconfig/flushdns

第三步 拉取nuxt脚手架

npx nuxi@latest init web

究极解决方案

如果上述方法还是不能解决问题,就使用下面这种方法

Githubfork官方nuxt脚手架初始化脚本

尽量使用GiteeGiteafork

fork之后获取对应路径为templates文件夹的**raw**路径

windows配置

在编辑环境变量

linux配置

export NUXI_INIT_REGISTRY="https://gitee.com/codepzj/nuxt-starter/raw/templates/templates"

总结

nuxt官方设置这个脚手架没有考虑全面,我认为应该将脚手架中这个配置文件的链接套一层cdn,防止被墙,所以脚手架通过raw.githubusercontent.com来拉取,被墙这种设计就非常不合理。