nuxt: Prerender errors on navigateTo

Environment


  • Operating System: Linux
  • Node Version: v16.20.0
  • Nuxt Version: 3.6.3
  • Nitro Version: 2.5.2
  • Package Manager: npm@9.4.2
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-rgxtrr?file=pages%2Findex.vue

Describe the bug

I’m using

<script setup>
navigateTo('/page2')
</script>

Rendering fails since 3.6.2 with this error:

 ERROR  Exiting due to prerender errors.                                                      10:02:09 PM

  at Module.prerender (node_modules/nitropack/dist/shared/nitro.1db3349c.mjs:204:11)
  at async eval (node_modules/nuxt/dist/index.mjs:2657:7)
  at async build (node_modules/nuxt/dist/index.mjs:3808:5)
  at async Object.invoke (node_modules/nuxi/dist/chunks/build.mjs:74:5)
  at async Object.invoke (node_modules/nuxi/dist/chunks/generate.mjs:51:5)
  at async _main (node_modules/nuxi/dist/cli.mjs:64:20)

Additional context

No response

Logs

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Now yes! I used “ssr: false” and the generate worked correctly. Thanks for help!

I found that if you used the following you could still use SSR for the rest of the application. Just in case you still needed to:

routeRules: { '/': {ssr: false} }

You will be able to do that as long as your server serves up the 200.html file. That will perform the redirect on client side.

Now yes! I used “ssr: false” and the generate worked correctly. Thanks for help!

Yes, it still fails to render because it is redirected within your own code (so there is no HTML to render). This has always been the behaviour. But by setting failOnError: false, it won’t finish with an error code so your CI will pass.