Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prerendering page that relies on route handlers fails #74525

Closed
jqvelin opened this issue Jan 4, 2025 · 1 comment
Closed

Prerendering page that relies on route handlers fails #74525

jqvelin opened this issue Jan 4, 2025 · 1 comment
Labels
bug Issue was opened via the bug report template.

Comments

@jqvelin
Copy link

jqvelin commented Jan 4, 2025

Link to the code that reproduces this issue

https://github.com/jqvelin/reproduction-app

To Reproduce

  1. Clone the repo, install required dependencies
  2. Run npm run build
  3. Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error ...

Current vs. Expected behavior

Expected successful build of the application, got crash instead.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 16088
  Available CPU cores: 16
Binaries:
  Node: 20.15.1
  npm: 10.7.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.1.1-canary.25 // Latest available version is detected (15.1.1-canary.25).
  eslint-config-next: 15.1.1-canary.25
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

Same code is being built well with next.js v14.2.22
image

@jqvelin jqvelin added the bug Issue was opened via the bug report template. label Jan 4, 2025
@icyJoseph
Copy link
Contributor

There's no server to handle the request. That's why it fails.

Other frameworks, such as Nuxt, use something called, Direct API calls, with a special $fetch function, which instead of fetching, invokes the route code, and collects the result. https://nuxt.com/docs/guide/concepts/server-engine#direct-api-calls

All in all, fetching from your API routes, as you render, is not a good practice. It implies a jump out to the internet and back to your app, which is bound to be slow... Just fetch the data you need, directly from source, as you render.

@jqvelin jqvelin closed this as completed Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

2 participants