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

I can't prerender routes with any template #12508

Closed
gmtborges opened this issue Dec 9, 2024 · 1 comment
Closed

I can't prerender routes with any template #12508

gmtborges opened this issue Dec 9, 2024 · 1 comment
Labels

Comments

@gmtborges
Copy link

gmtborges commented Dec 9, 2024

I'm using React Router as a...

framework

Reproduction

I'd like to prerender some routes like terms, privacy, about-us. But when I setup react-router.config.ts I got an error on building.

I just npx create-react-router@latest and change react-router.config.ts like this:

import type { Config } from "@react-router/dev/config";

export default {
  // Config options...
  // Server-side render by default, to enable SPA mode set this to `false`
  ssr: true,
  async prerender() {
    return ["/"];
  },
} satisfies Config;

It is happen on StackBlitz too

Open in StackBlitz

The error with default template

x Build failed in 85ms
[react-router] Prerender: Received a 500 status code from `entry.server.tsx` while prerendering the `/` path.
Unexpected Server Error
    at validatePrerenderedResponse (/Users/gustavo/repos/estudos/js/rr-default/node_modules/@react-router/dev/dist/vite.js:2635:11)
    at prerenderRoute (/Users/gustavo/repos/estudos/js/rr-default/node_modules/@react-router/dev/dist/vite.js:2599:3)
    at handlePrerender (/Users/gustavo/repos/estudos/js/rr-default/node_modules/@react-router/dev/dist/vite.js:2525:7)
    at Object.handler (/Users/gustavo/repos/estudos/js/rr-default/node_modules/@react-router/dev/dist/vite.js:2029:13)
    at async Promise.all (index 0)
    at PluginDriver.hookParallel (file:///Users/gustavo/repos/estudos/js/rr-default/node_modules/rollup/dist/es/shared/node-entry.js:20740:9)
    at file:///Users/gustavo/repos/estudos/js/rr-default/node_modules/rollup/dist/es/shared/node-entry.js:21783:13
    at catchUnfinishedHookActions (file:///Users/gustavo/repos/estudos/js/rr-default/node_modules/rollup/dist/es/shared/node-entry.js:21158:16)
    at Module.build (file:///Users/gustavo/repos/estudos/js/rr-default/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:65449:16)
    at viteBuild (/Users/gustavo/repos/estudos/js/rr-default/node_modules/@react-router/dev/dist/cli/index.js:1204:5) {
  code: 'PLUGIN_ERROR',
  plugin: 'react-router',
  hook: 'writeBundle'
}

The error with cloudflare template

x Build failed in 429ms
[react-router] Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at groupRoutesByParentId2 (/Users/gustavo/repos/estudos/js/rr-cloudflare/node_modules/@react-router/dev/dist/vite.js:2650:10)
    at createPrerenderRoutes (/Users/gustavo/repos/estudos/js/rr-cloudflare/node_modules/@react-router/dev/dist/vite.js:2661:76)
    at handlePrerender (/Users/gustavo/repos/estudos/js/rr-cloudflare/node_modules/@react-router/dev/dist/vite.js:2477:16)
    at Object.handler (/Users/gustavo/repos/estudos/js/rr-cloudflare/node_modules/@react-router/dev/dist/vite.js:2029:13)
    at async Promise.all (index 0)
    at PluginDriver.hookParallel (file:///Users/gustavo/repos/estudos/js/rr-cloudflare/node_modules/rollup/dist/es/shared/node-entry.js:20740:9)
    at file:///Users/gustavo/repos/estudos/js/rr-cloudflare/node_modules/rollup/dist/es/shared/node-entry.js:21783:13
    at catchUnfinishedHookActions (file:///Users/gustavo/repos/estudos/js/rr-cloudflare/node_modules/rollup/dist/es/shared/node-entry.js:21158:16)
    at Module.build (file:///Users/gustavo/repos/estudos/js/rr-cloudflare/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:65449:16) {
  code: 'PLUGIN_ERROR',
  plugin: 'react-router',
  hook: 'writeBundle'
}

System Info

System:
    OS: macOS 14.7
    CPU: (11) arm64 Apple M3 Pro
    Memory: 169.31 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.asdf/installs/nodejs/20.11.1/bin/node
    npm: 10.2.4 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.14.4 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 131.0.6778.109
    Safari: 17.6
  npmPackages:
    @react-router/dev: ^7.0.2 => 7.0.2
    @react-router/node: ^7.0.2 => 7.0.2
    @react-router/serve: ^7.0.2 => 7.0.2
    react-router: ^7.0.2 => 7.0.2
    vite: ^5.4.11 => 5.4.11

Used Package Manager

npm

Expected Behavior

I should prerender any route I want.

Actual Behavior

There isn't possible to prerender in any template.

@gmtborges gmtborges added the bug label Dec 9, 2024
@brookslybrand
Copy link
Contributor

@gmtborges sorry about that! I missed a part of the templates when I updated to 19 and we discovered this issue

Change your build command to:

"build": "cross-env NODE_ENV=production react-router build"

Thanks again for opening the issue. The templates should be fixed now, but please do open an issue in react-router-templates if not

Additionally, the underlying issue was pointed out in #12138 and is being addressed in #12505, so I'm going to go ahead and close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants