router icon indicating copy to clipboard operation
router copied to clipboard

Prerender fails when using custom base path - attempts to fetch / instead of configured base path

Open busy-dog opened this issue 1 month ago • 0 comments

Which project does this relate to?

Start

Describe the bug

When configuring a custom base path in Vite along with TanStack Router's basepath, the prerenderer still attempts to crawl from / instead of the configured base path, resulting in a "Failed to fetch /: Not Found" error during build.

Your Example Website or App

https://github.com/busy-dog/tanstack-start-demo

Steps to Reproduce the Bug or Issue

  1. Configure a custom base path in vite.config.ts:
const BASEPATH = '/gitlab/34e28e1e78c44601b0974c2097b85a27/caelum-doc-dist/';

export default defineConfig({
  base: BASEPATH,
  define: {
    BASEPATH: JSON.stringify(BASEPATH),
  },
  plugins: [
    tanstackStart({
      spa: {
        enabled: true,
        prerender: {
          outputPath: 'index.html',
          enabled: true,
          crawlLinks: false,
        },
      },
      pages: [
        { path: `/docs` },
        { path: `/api/search` },
      ],
    }),
  ],
});
  1. Configure router with basepath in router.tsx:
export function getRouter() {
  return createTanStackRouter({
    routeTree,
    basepath: BASEPATH,
    // ... other options
  });
}
  1. Run vite build

Build fails during prerender phase with:

[prerender] Crawling: /
error: Failed to fetch /: Not Found
  at <anonymous> (/node_modules/@tanstack/start-plugin-core/dist/esm/prerender.js:126:23)

Expected behavior

The prerenderer should respect the configured base path and attempt to fetch from /gitlab/34e28e1e78c44601b0974c2097b85a27/caelum-doc-dist/ instead of /.

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.139.14
  • OS: macOS
  • Browser: Chrome
  • Browser Version: 141
  • Bundler: vite
  • Bundler Version: 7.2.6

Additional context

No response

busy-dog avatar Dec 05 '25 02:12 busy-dog