Skip to content

using routes outside directory breaks typegen #14442

@fernandojbf

Description

@fernandojbf

Reproduction

Description

When using routes located outside the app directory, the type generator produces incorrect type paths due to the way the app directory is being resolved

As a result, when such external routes are included in the +routes.ts RouteModules type, import errors occur.

This issue primarily affects shared routes distributed via node_modules, which are often used in modular or multi-app setups. I know that, for now, the framework does not officially support this use case, but it’s still possible to reference them using file system paths.

Proposed Solution

React Router’s type generator explicitly skips any route defined outside the app directory.

Assign a fallback type (e.g., unknown) to any route module whose type definition was not generated.
This ensures type safety while maintaining compatibility with shared routes or unconventional project structures.

PR here: #14439

System Info

System:
    OS: macOS 15.7.1
    CPU: (12) arm64 Apple M2 Pro
    Memory: 145.45 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.13.1 - ~/.nvm/versions/node/v22.13.1/bin/node
    Yarn: 4.10.3 - ~/.nvm/versions/node/v22.13.1/bin/yarn
    npm: 11.5.2 - ~/.nvm/versions/node/v22.13.1/bin/npm
    bun: 1.2.2 - ~/.bun/bin/bun
    Watchman: 2024.11.11.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 141.0.7390.66
    Chrome Canary: 143.0.7465.0
    Safari: 26.0.1

Used Package Manager

yarn

Expected Behavior

Type generation should gracefully handle routes outside the app directory, allowing shared or external route modules to be referenced without errors.

Actual Behavior

wrong path is been added to type import() in RouteModule

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions