Skip to content

Empty .ts route file is scaffolded with JSX, breaking all route generation #8480

Description

@nathan-logan

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

  1. Clone the repo
  2. pnpm install
  3. pnpm generate-routes
  4. Fails with SyntaxError: Missing semicolon. (8:19), foo.ts is empty and routeTree.gen.ts was 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions