Skip to content

Calling flatRoutes() from app code results in an invariant Error #13086

@leondmello

Description

@leondmello

I'm using React Router as a...

framework

Reproduction

Go to https://stackblitz.com/edit/github-a7kuzc3f?file=app%2Fentry.server.tsx and run:

npm run build && npm run start

System Info

npx envinfo --system --npmPackages '{vite,react-router,@react-router/*}' --binaries --browsers
  System:
    OS: macOS 15.3
    CPU: (10) arm64 Apple M1 Pro
    Memory: 106.83 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.13.1 - ~/.nodenv/versions/22.13.1/bin/node
    npm: 10.9.2 - ~/.nodenv/versions/22.13.1/bin/npm
  Browsers:
    Chrome: 133.0.6943.127
    Safari: 18.3
  npmPackages:
    @react-router/dev: ^7.1.1 => 7.1.3 
    @react-router/fs-routes: ^7.1.1 => 7.1.3 
    @react-router/node: ^7.1.1 => 7.1.3 
    @react-router/serve: ^7.1.1 => 7.1.3 
    react-router: ^7.1.1 => 7.1.5 
    vite: ^5.4.11 => 5.4.14

Used Package Manager

npm

Expected Behavior

App should start

Actual Behavior

Fails to start

> start
> react-router-serve ./build/server/index.js

[react-router-serve] http://localhost:3000 (http://192.168.1.104:3000)
The following error is a bug in React Router; please open an issue! https://github.com/remix-run/react-router/issues/new/choose

/home/projects/llqiwvkkxr.github/node_modules/@react-router/dev/dist/routes.js:63
    throw new Error(message);
          ^
Error: 
    at invariant (/home/projects/llqiwvkkxr.github/node_modules/@react-router/dev/dist/routes.js:63:11)
    at getAppDirectory (/home/projects/llqiwvkkxr.github/node_modules/@react-router/dev/dist/routes.js:69:3)
    at Module.flatRoutes2 (/home/projects/llqiwvkkxr.github/node_modules/@react-router/fs-routes/dist/index.js:464:56)
    at onShellReady (file:///home/projects/llqiwvkkxr.github/build/server/index.js:47:53)
    at completeShell (/home/projects/llqiwvkkxr.github/node_modules/react-dom/cjs/react-dom-server.node.production.js:5235:3)
    at finishedTask (/home/projects/llqiwvkkxr.github/node_modules/react-dom/cjs/react-dom-server.node.production.js:5271:39)
    at performWork (/home/projects/llqiwvkkxr.github/node_modules/react-dom/cjs/react-dom-server.node.production.js:5404:15)
    at AsyncLocalStorage.run (node:async_hooks:18:3866)
    at eval (/home/projects/llqiwvkkxr.github/node_modules/react-dom/cjs/react-dom-server.node.production.js:5878:27)
    at node:internal/process/task_queues:192:1778

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions