Repository navigation
Description
Which project does this relate to?
Start
Describe the bug
When using TanStack Start with nitro's vercel preset and prerender enabled, the build fails during the prerender phase. The preview server starts successfully via srvx, but when attempting to fetch pages for prerendering, srvx throws a TypeError because this.runtime.node is undefined.
This happens because nitro's vercel preset generates serverless function output designed for Vercel's runtime environment. The prerender step uses srvx to start a local Node.js preview server, but srvx's Node adapter expects this.runtime.node to exist - which it doesn't when running Vercel-formatted functions locally.
Your Example Website or App
Minimal vite.config.ts to reproduce:
import { defineConfig } from 'vite'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import { nitro } from 'nitro/vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [
tanstackStart({
prerender: {
enabled: true,
},
}),
nitro({ preset: 'vercel' }),
react(),
],
})Steps to Reproduce the Bug or Issue
- Create a TanStack Start project
- Install nitro nightly:
npm add nitro@npm:nitro-nightly@latest - Configure vite.config.ts with:
nitro({ preset: 'vercel' })tanstackStart({ prerender: { enabled: true } })
- Run
vite build
Expected behavior
Build should complete successfully, either by:
- Prerendering pages correctly, or
- Detecting serverless preset and skipping prerender with a warning
Actual behavior
Build fails during prerender with:
ℹ Spawning preview server...
ℹ npx srvx --static ../../static ./functions/__server.func/index.mjs
➜ Listening on: http://localhost:36889/ (all interfaces)
[prerender] Concurrency: 14
[prerender] Crawling: /
TypeError: Cannot destructure property 'req' of 'this.runtime.node' as it is undefined.
at get _abortController (file:///project/node_modules/srvx/dist/adapters/node.mjs:210:13)
at get signal (file:///project/node_modules/srvx/dist/adapters/node.mjs:225:55)
at renderRouterToStream (file:///project/.vercel/output/functions/__server.func/_chunks/_libs/@tanstack/react-router.mjs:506:23)
...
[prerender] Prerendered 0 pages:
Error: Failed to fetch /: Internal Server Error
at file:///project/node_modules/@tanstack/start-plugin-core/dist/esm/prerender.js:137:19
Screenshots or Videos
N/A
Platform
- TanStack Start Version: 1.157.18
- nitro Version: 3.0.1-20260131-134752-eea737f2 (nightly)
- OS: Linux
- Node: v25.0.0
- Bundler: vite 7.3.1
Additional context
Root cause analysis:
The nitro vercel preset outputs to .vercel/output/functions/__server.func/ which is designed for Vercel's serverless runtime. When prerender starts a preview server via srvx (npx srvx --static ../../static .vercel/output/functions/__server.func/index.mjs), the srvx Node adapter tries to access this.runtime.node.req for the abort controller, but the runtime context doesn't exist because the function wasn't invoked through Vercel's runtime.
The key issue is that srvx assumes a Node.js runtime context, but Vercel-preset output expects Vercel's serverless runtime context.
Workaround:
Disable prerender when using the vercel preset:
tanstackStart({
prerender: {
enabled: false,
},
}),
nitro({ preset: 'vercel' }),Vercel handles SSR dynamically at request time, so prerender isn't strictly necessary.
Possible solutions:
- Detect vercel/cloudflare/serverless presets and automatically skip prerender (or warn)
- Use a node-compatible build for prerender, then switch to vercel preset for final output
- Document that prerender is incompatible with serverless presets
Related issues:
- nitro + spa mode breaks since v1.138.0 #5967 (nitro + spa mode breaks) - similar prerender issue, fixed in fix: prerendering #6256
- Prerendering appears broken in latest #6322 (Prerendering appears broken in latest)
Activity
LeonardoTrapani commentedon Jan 31, 2026
Update: Found the upstream issue tracking this:
PR #3921 was merged to add the srvx preview command, but the issue is still open because prerender + vercel preset still fails with the
runtime.nodeerror we're seeing here.This appears to be a known limitation of the nitro + vercel preset when used with prerender. The workaround is to disable prerender when deploying to Vercel (Vercel handles SSR dynamically anyway).
armandsalle commentedon Mar 1, 2026
Root Cause: Nitro's Vercel Web handler overwrites
runtime.nodeI hit this exact crash while deploying a TanStack Start app to Vercel with Nitro
3.0.1-alpha.2and traced the root cause.Diagnosis
When using the Vercel web entry (
vercel.web.mjs), the handler does:This completely overwrites the
runtimeobject, destroyingruntime.node = { req, res }previously set by srvx. When TanStack Router'srenderRouterToStreamlater accessesthis.runtime.node.req(via srvx's_abortControllergetter), it crashes:This also affects prerendering — same crash during build.
Workaround
Force Nitro to use the Node.js entry format instead of the Web handler:
This uses
vercel.node.mjsinstead, which doesn't touchruntime.node.Upstream fix suggestion
The bug is in Nitro —
vercel.web.mjsshould merge intoreq.runtimeinstead of replacing it:Related: nitrojs/nitro#3905 (closed with incomplete diagnosis)
fix(nitro): upgrade to 3.0.260311-beta — fix Vercel 508 infinite loop
fix: disable prerendering for docs to fix Vercel build
fix: nitro vercel entryFormat "node" — self-fetch loop root cause