美文网首页
Nuxt 报错 Failed to download https

Nuxt 报错 Failed to download https

作者: 南土酱 | 来源:发表于2024-07-30 10:56 被阅读0次

    转载于 这位大佬 (好文章帮忙提升曝光率,有些博客网站吃相太难看)

    Nuxt 项目安装时报错(TypeError: fetch failed)的解决 (jsnoteclub.com)

    在安装 Nuxt 项目时报错:ERROR Error: Failed to download template from registry: Failed to download https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json: TypeError: fetch failed.

    报错原因

    可能是因为国内的网络政策,对 raw.githubusercontent.com 进行了 DNS 污染,这会导致你的请求在到达 DNS 服务器后解析到错误的服务器 IP 地址,从而无法正确连接到 githubusercontent 的服务,所以当 ping 这个地址的时候也是 ping 不通的(ping raw.githubusercontent.com)。

    解决办法:在本地配 Host

    在本地的 hosts 文件中新加一行配置,即可解决报错问题:

    185.199.108.133 raw.githubusercontent.com
    

    上面的配置可以模拟 DNS,这里的 IP 地址你可以在https://sites.ipaddress.com/raw.githubusercontent.com/查到,不过通常都是185.199.108.133,关于配置方法,见下文。

    Windows

    下面是在 Windows 中编辑 Hosts 文件的步骤:

    1.打开 Notepad 作为管理员

    在开始菜单中搜索 "Notepad",右键点击 "Notepad" 并选择 "以管理员身份运行"。

    2.打开 Hosts 文件

    在 Notepad 中,点击 "文件" 菜单,然后选择 "打开"。导航到以下路径:C:\Windows\System32\drivers\etc\, 然后打开"hosts"文件。

    3.编辑 Hosts 文件

    在文件的末尾添加新的行,每行的格式是 IP 地址,空格,域名,将下面的配置添加进去即可。

    185.199.108.133 raw.githubusercontent.com
    

    这会将 raw.githubusercontent.com 映射到主机(185.199.108.133)。

    4.保存文件

    在 Notepad(记事本) 中编辑完 Hosts 文件后,保存即可。

    5.创建 Nuxt 项目:

    Hosts 配置后,我们可以再 ping 一下(ping raw.githubusercontent.com),发现成功了:

    Nuxt 项目也创建成功( npx nuxi@latest init next-demo

    (好文章帮忙提升曝光率,有些博客网站吃相太难看)
    Nuxt 项目安装时报错(TypeError: fetch failed)的解决 (jsnoteclub.com)

    相关文章

      网友评论

          本文标题:Nuxt 报错 Failed to download https

          本文链接:https://www.haomeiwen.com/subject/mmcghjtx.html