Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error while deploying nuxt 3 in pre-rendered mode

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

like image 458
Mohammad Avatar asked Apr 24 '26 05:04

Mohammad


1 Answers

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 },
  },
});
like image 174
Mohammad Avatar answered Apr 26 '26 01:04

Mohammad