nitro + spa mode breaks since v1.138.0
Which project does this relate to?
Start
Describe the bug
If you use nitro + spa mode, the vite build will report this error:
✓ built in 535ms
[prerender] Prerendering pages...
error during build:
Error: Failed to start the Vite preview server for prerendering
at startPreviewServer (file:///project-dir/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_4811f95400dc016e184359a72f378162/node_modules/@tanstack/start-plugin-core/dist/esm/prerender.js:195:11)
at async prerender (file:///project-dir/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_4811f95400dc016e184359a72f378162/node_modules/@tanstack/start-plugin-core/dist/esm/prerender.js:42:25)
at async postServerBuild (file:///project-dir/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_4811f95400dc016e184359a72f378162/node_modules/@tanstack/start-plugin-core/dist/esm/post-server-build.js:38:5)
at async BasicMinimalPluginContext.handler (file:///project-dir/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_4811f95400dc016e184359a72f378162/node_modules/@tanstack/start-plugin-core/dist/esm/plugin.js:267:11)
at async Object.buildApp (file:///project-dir/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/config.js:34542:5)
at async CAC.<anonymous> (file:///project-dir/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/cli.js:629:3)
 ELIFECYCLE  Command failed with exit code 1.
Your Example Website or App
https://github.com/ImSingee/tanstack-start-bug-reproduce-for-spa
Steps to Reproduce the Bug or Issue
- Setup nitro with tanstack start (https://tanstack.com/start/latest/docs/framework/react/guide/hosting#nitro)
- Enable SPA mode (https://tanstack.com/start/latest/docs/framework/react/guide/spa-mode)
Expected behavior
Build should be success
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.139.6
- OS: macOS
- Bundler: vite
- Bundler Version: ^7.2.4
Additional context
I created a bug-reproduce repo with the latest version, but I can confirm the issue starts at v1.138.0 after #5921 is merged.
After executing the pnpm build (failed), then execute npx vite preview, this error occurs:
error when starting preview server:
Error: Cannot load nitro build info. Make sure to build first.
at BasicMinimalPluginContext.error (file:///project-dir/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/config.js:29511:35)
at BasicMinimalPluginContext.configurePreviewServer (file:///project-dir/node_modules/.pnpm/[email protected][email protected][email protected]_@[email protected][email protected][email protected][email protected]_/node_modules/nitro/dist/_build/vite.plugin.mjs:443:31)
at async preview (file:///project-dir/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/config.js:35765:93)
at async CAC.<anonymous> (file:///project-dir/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/cli.js:669:18)
hey I have same issue with nitro and this looks like broke when using nit "nitro": "^3.0.1-alpha.1" when switch back to @tanstack/nitro-v2-vite-plugin this works as expectd:
Output "nitro": "^3.0.1-alpha.1":
Output "@tanstack/nitro-v2-vite-plugin": "^1.139.0":
I had this issue as well for a few hours but only when building on vercel, not locally.
I am also using SPA-mode and nitro v3 preview.
My error in vercel build logs:
[prerender] Prerendering pages...
error during build:
Error: Failed to start the Vite preview server for prerendering
at startPreviewServer (file:///vercel/path0/node_modules/.bun/@[email protected]+455187427322a990/node_modules/@tanstack/start-plugin-core/dist/esm/prerender.js:195:11)
at async prerender (file:///vercel/path0/node_modules/.bun/@[email protected]+455187427322a990/node_modules/@tanstack/start-plugin-core/dist/esm/prerender.js:42:25)
at async postServerBuild (file:///vercel/path0/node_modules/.bun/@[email protected]+455187427322a990/node_modules/@tanstack/start-plugin-core/dist/esm/post-server-build.js:38:5)
at async BasicMinimalPluginContext.handler (file:///vercel/path0/node_modules/.bun/@[email protected]+455187427322a990/node_modules/@tanstack/start-plugin-core/dist/esm/plugin.js:267:11)
at async Object.buildApp (file:///vercel/path0/node_modules/.bun/[email protected]+fad1561be79d52d9/node_modules/vite/dist/node/chunks/config.js:34542:5)
at async CAC.<anonymous> (file:///vercel/path0/node_modules/.bun/[email protected]+fad1561be79d52d9/node_modules/vite/dist/node/cli.js:629:3)
error: script "build" exited with code 1
Error: Command "bun run build" exited with 1
I resolved it by downgrading all the router and start packages to 1.136.18
"@tanstack/react-router": "1.136.18",
"@tanstack/react-router-devtools": "1.136.18",
"@tanstack/react-router-ssr-query": "1.136.18",
"@tanstack/react-start": "1.136.18",
It isn't a real solution but i cant spend any more time on it.
For me using the @tanstack/nitro-v2-vite-plugin raised another issue but i could see that being a workaround for some people.
I'm also getting the same issue. Doing the downgrade fixes it. Happens on nitro + spa on version >1.136 for me too.
faced the same problem, it's not SPA but has simple pre-rendering, and server function referenced in loader. Probably not specific to SPA.
Still seeing issue
const config = defineConfig({
plugins: [
devtools(),
nitro(),
// this is the plugin that enables path aliases
viteTsConfigPaths({
projects: ['./tsconfig.json'],
}),
tailwindcss(),
tanstackStart({
spa: {
enabled: true
}
}),
viteReact(),
],
})
https://github.com/ShoeBoom/tanstack-nitro-spa-bug https://stackblitz.com/~/github.com/ShoeBoom/tanstack-nitro-spa-bug
pnpm build results in
Error: Failed to start the Vite preview server for prerendering
at startPreviewServer (file:///home/ShoeBoom/tanstack-nitro-spa-bug/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@tanstack/start-plugin-core/dist/esm/prerender.js:210:11)
at async Module.prerender (file:///home/ShoeBoom/tanstack-nitro-spa-bug/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@tanstack/start-plugin-core/dist/esm/prerender.js:57:25)
at async Module.postServerBuild (file:///home/ShoeBoom/tanstack-nitro-spa-bug/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@tanstack/start-plugin-core/dist/esm/post-server-build.js:53:5)
at async BasicMinimalPluginContext.handler (file:///home/ShoeBoom/tanstack-nitro-spa-bug/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@tanstack/start-plugin-core/dist/esm/plugin.js:284:11)
at async Object.buildApp (file:///home/ShoeBoom/tanstack-nitro-spa-bug/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/config.js:33992:5)
at async CAC.eval (file:///home/ShoeBoom/tanstack-nitro-spa-bug/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/cli.js:644:3)
 ELIFECYCLE  Command failed with exit code 1.