Empty .ts route file is scaffolded with JSX, breaking all route generation #8480
Send to my agentWhich project does this relate to?#
Router
Describe the bug#
Creating an empty .ts route file breaks all route generation, and it does not recover on subsequent runs.
The react and solid templates both contain a JSX component. The generator then transforms the file it has just written and it fails to parse its own output.
Error: Error transforming route file /src/routes/api/foo.ts: SyntaxError: Missing semicolon. (8:19)
at /node_modules/.pnpm/@tanstack+router-generator@1.167.38/node_modules/@tanstack/router-generator/dist/cjs/generator.cjs:147:13
at async Object.generate (/tanstack-start-ts-route-generation/node_modules/.pnpm/@tanstack+router-cli@1.167.38/node_modules/@tanstack/router-cli/dist/cjs/generate.cjs:5:3)
at async /tanstack-start-ts-route-generation/node_modules/.pnpm/@tanstack+router-cli@1.167.38/node_modules/@tanstack/router-cli/dist/cjs/index.cjs:13:3
[ELIFECYCLE] Command failed with exit code 1.
Complete minimal reproducer#
https://github.com/nathan-logan/tanstack-start-ts-route-generation
Steps to Reproduce the Bug#
- Clone the repo
pnpm installpnpm generate-routes- Fails with
SyntaxError: Missing semicolon. (8:19),foo.tsis empty androuteTree.gen.tswas never written.
Expected behavior#
I expected an empty .ts route file to be boilerplated with valid TypeScript. Instead it breaks route generation entirely.
Screenshots or Videos#
No response
Platform#
- Router / Start Version: 1.170.38 (router-generator Version: 1.167.38)
- OS: Linux
- Browser: N/A
- Browser Version: N/A
- Bundler: vite
- Bundler Version: 8.3.0
- Node version: v24.13.0
Additional context#
I have a fix prepared and can open a PR. Only question is around what a .ts file boilerplate should be, I have opted for createFileRoute('/api/foo')({}) on the grounds that a .ts route is almost always a server route and a component can't be added without renaming to .tsx anyway. I use TanStack quite a bit so would still like to see .ts files supported, in previous versions I would just remove the JSX from the template manually after it was inserted.
Side note: I did find that PR #7872 is also open against template.ts and touches the same code I have, but it is unrelated.
nathan-logan(GitHub profile, opens in a new tab) linked this to #8481
Sheraff(GitHub profile, opens in a new tab) linked this to #8817
Sign in to join this conversation.