Nuxt 3 在预渲染模式下部署时出现错误。

huangapple go评论78阅读模式
英文:

error while deploying nuxt 3 in pre-rendered mode

问题

抱歉,由于代码部分涉及代码标记和特殊字符,我无法提供准确的翻译。但是,我可以为你提供一些关于问题的指导建议。

首先,根据错误消息,你的应用似乎在预渲染时遇到了404错误。这可能是因为你的预渲染配置中引用了一个无法访问的页面。请检查以下几个方面:

  1. 页面路径问题: 确保你的页面路径是正确的。在Nuxt.js中,默认情况下,页面应该放在/pages目录中,但你也可以使用自定义路由配置。

  2. 基本URL设置: 你的nuxt.config.ts中有一个baseURL设置为http://localhost:8000。请确保这个URL是正确的,可以在浏览器中访问该URL以确认是否可以正常加载。

  3. Prerender配置: 你的nuxt.config.ts中有一个prerender配置,确保它正确设置。可能需要检查是否有其他配置选项或路由规则与预渲染冲突。

  4. 404页面: 确保你的404页面在正确的位置,并且与路由配置匹配。通常,Nuxt.js会自动处理404页面,但你需要确保它放置在/pages/404.vue或按照你的路由配置放置。

如果你确认上述配置都正确,但仍然遇到问题,你可能需要查看更多的日志信息,以便确定问题的根本原因。你可以尝试查看Nuxt.js的文档或社区论坛,以获取更多关于预渲染错误的信息和解决方法。

希望这些指导建议能帮助你解决问题。如果你需要更详细的帮助,请提供更多关于你的Nuxt.js应用程序和配置的信息,以便我能够提供更具体的建议。

英文:

Hi I'm trying to build my nuxt 3 app in pre-rendered mode (SSG mode), and I have add these configs in my nuxt.config.ts file


// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },

  runtimeConfig: {
    public: {
      WEBSITE_NAME_EN: process.env.WEBSITE_NAME_EN,
      WEBSITE_ADDRESS: process.env.WEBSITE_ADDRESS,
      API_BASE_URL: process.env.API_BASE_URL,
    },
  },

  ssr: true,
  nitro: {
    baseURL: "http://localhost:8000",
    prerender: {
      crawlLinks: true,
    },
  },
  routeRules: {
    "/**": { swr: true },
    "/dashboard/**": { ssr: false },
  },
});


and my package.json file content


{
  "name": "nuxt-app",
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "devDependencies": {
    "@ckeditor/ckeditor5-vue": "^5.1.0",
    "@fortawesome/fontawesome-free": "^6.4.0",
    "@nuxt/devtools": "latest",
    "@nuxtjs/tailwindcss": "^6.8.0",
    "@pinia/nuxt": "^0.4.11",
    "@types/node": "^18.16.19",
    "@vee-validate/rules": "^4.10.8",
    "@vime/core": "^5.4.1",
    "@vime/vue-next": "^5.4.1",
    "@vueuse/nuxt": "^10.2.1",
    "axios": "^1.4.0",
    "nuxt": "^3.6.5",
    "pinia": "^2.1.4",
    "sass": "^1.64.1",
    "sass-loader": "^13.3.2",
    "swiper": "^10.0.4",
    "v-lazy-image": "^2.1.1",
    "vee-validate": "^4.10.8",
    "vue-toastification": "^2.0.0-rc.5"
  }
}

but when I run yarn build command it produces these errors


  built in 7.26s                                                                                                                                                                                                            11:57:59 AM
 Server built in 7284ms                                                                                                                                                                                                      11:57:59 AM
 Generated public .output/public                                                                                                                                                                                       nitro 11:57:59 AM
 Initializing prerenderer                                                                                                                                                                                              nitro 11:57:59 AM
 Prerendering 1 initial routes with crawler                                                                                                                                                                            nitro 11:58:06 AM
  ├─ / (144ms) (Error: [404] Page not found: /http://localhost:8000)                                                                                                                                                     nitro 11:58:07 AM
                                                                                                                                                                                                                         nitro 11:58:07 AM
Errors prerendering:
  ├─ / (404)                                                                                                                                                                                                             nitro 11:58:07 AM
                                                                                                                                                                                                                         nitro 11:58:07 AM

 ERROR  Exiting due to prerender errors.                                                                                                                                                                                       11:58:07 AM

  at prerender (/E:/Workspace/personal-website-frontend-v2/node_modules/nitropack/dist/shared/nitro.1db3349c.mjs:189:11)
  at runMicrotasks (<anonymous>)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)
  at async /E:/Workspace/personal-website-frontend-v2/node_modules/nuxt/dist/index.mjs:2641:7
  at async build (/E:/Workspace/personal-website-frontend-v2/node_modules/nuxt/dist/index.mjs:3794:5)
  at async Object.invoke (/E:/Workspace/personal-website-frontend-v2/node_modules/nuxi/dist/chunks/build.mjs:59:5)
  at async _main (/E:/Workspace/personal-website-frontend-v2/node_modules/nuxi/dist/cli.mjs:49:20)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I have a 404 page at this address /pages/404.vue but it still gives me this error, so what is the problem and how can I fix it?

I couldn't find any answer, and the problem seems so weird to me

EDIT: I even made a new project and I add nuxt.config.ts content to that but still, the same error exist

答案1

得分: 4

I've added failOnError: false to prerender object in nuxt.config.ts file and the build was successful but the error still exists and I couldn't find any answer for it.

Now my nuxt.config.ts content are like this:


// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },

  runtimeConfig: {
    public: {
      WEBSITE_NAME_EN: process.env.WEBSITE_NAME_EN,
      WEBSITE_ADDRESS: process.env.WEBSITE_ADDRESS,
      API_BASE_URL: process.env.API_BASE_URL,
    },
  },

  ssr: true,
  nitro: {
    baseURL: "http://localhost:8000",
    prerender: {
      crawlLinks: true,
      failOnError: false, 
    },
  },
  routeRules: {
    "/**": { swr: true },
    "/dashboard/**": { ssr: false },
  },
});

Note: There is another answer to this question that you can see it down below

英文:

I've added failOnError: false to prerender object in nuxt.config.ts file and the build was successful but the error still exists and I couldn't find any answer for it.

Now my nuxt.config.ts content are like this:


// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },

  runtimeConfig: {
    public: {
      WEBSITE_NAME_EN: process.env.WEBSITE_NAME_EN,
      WEBSITE_ADDRESS: process.env.WEBSITE_ADDRESS,
      API_BASE_URL: process.env.API_BASE_URL,
    },
  },

  ssr: true,
  nitro: {
    baseURL: "http://localhost:8000",
    prerender: {
      crawlLinks: true,
      failOnError: false, 
    },
  },
  routeRules: {
    "/**": { swr: true },
    "/dashboard/**": { ssr: false },
  },
});

<b>Note:</b> There is another answer to this question that you can see it down below

答案2

得分: 0

我解决了这个问题,我的前端代码没有错误,问题出在我的Laravel后端API上,我在那里设置了一个throttle来限制我的API端点的请求次数,因此由于发送了许多请求,我遇到了404429错误,所以我在那里注释掉了throttle,问题就解决了。

注意:如果你不知道什么是throttle,在Nutshall中,throttle是Laravel中的请求限制器,例如,当你在一分钟内发送了10个请求时,它会限制你在一段时间内发送第11个请求。

英文:

I solve the problem, there was no error about my front-end code, it was from my Laravel back-end API, I had set a throttle there for my API endpoints, so because of sending many requests I had take404 and 429 errors so I comment throttle there and the problem got fixed

Note: if you don't know what throttle is, in Nutshall throttle is a request limiter in Laravel for instance when you send 10 requests in one minute it will limit you from the 11th request for some time.

huangapple
  • 本文由 发表于 2023年7月24日 16:38:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76752732.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定