Empty .ts route file is scaffolded with JSX, breaking all route generation
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- react, typescript
Research direction
The issue is in the route file generator. Look at the templates for 'react' and 'solid' in the router-generator package, likely in a templates directory. The bug is that an empty .ts file gets a JSX template, which fails to parse. Examine the generator code that selects and writes the template. The fix is to ensure .ts files get a valid TypeScript template, not JSX. Test by running the reproducer steps after making changes.
Written by the indexing model from the issue text.
Description
Which 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.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TanStack/router
-
information needed
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
lazyRouteComponent reload guard key collides on Safari, capping stale-deploy recovery at one per tab Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
information needed
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
bcgov/bc-wallet-mobile#4761 · 1 comment ·
-
external-issue to-triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
area-deployment area-integrations triage:bot-seen
Difficulty 2/5 Half a day Newbie friendliness 86/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
refactor
Difficulty 2/5 1-3 hours Newbie friendliness 84/100