Nuxt3初始化项目遇到的问题

173 阅读1分钟

根据Nuxt官网描述的初始化项目的步骤需注意以下几点:

  • Nodejs -v16.10.0以上。
  • 最好使用Visual Studio Code代码编辑器,并且使用它的Volar扩展。
  • 直接在编辑器的终端中运行项目。
  • 打开Visual Studio Code在其终端中输入以下代码:
npx nuxi@latest init your project name
  • 当执行这个代码时如果是windows操作系统容易出现两种错误提示:
  ERROR  Error: Failed to download template from registry: request to https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json failed, reason: getaddrinfo ENOENT raw.githubusercontent.com
  Error: Failed to download template from registry: fetch failed

出现以上两种错误是由于本身Nuxt是国外网站容易被墙,不能访问IP地址导致,解决方法可以参考如下几步:

  1. 在自己的windows系统的cmd中输入以下代码,查看是否能正确运行,如果不能访问,说明被墙,少了IP地址,可以先访问这个地址raw.githubusercontent.com/nuxt/starte… 找到对应的ip地址如下图:
image.png
ping raw.githubusercontent.com

2.如果1中无法访问,直接在C:/windows/System32/drivers/etc中打开hosts文件夹,在其最后添加一行代码配置项:

185.199.110.133 raw.githubusercontent.com

3.重新运行1中的代码ping raw.githubusercontent.com可以看到在cmd中打印出了以下图片中的几行代码,说明连接访问成功。

image.png 4.接着可以执行Nuxt官网中的初始化项目的代码了,可以初始化成功了。

npx nuxi@latest init your project name
cd your project name
npm run dev