Skip to content

Bug: path aliases don't get correctly resovlved in routes.ts #14091

@akamfoad

Description

@akamfoad

TL;DR

All imports in routes.ts and all its direct or transitive imports have to be absolute or relative using ./ and ../ notation, path aliases like ~ and @ aren't resolved correctly.

The issue

Vite and TypeScript allows defining aliases to relatively access files without using ./ or ../ notation, this is pretty significant for complex apps at scale as imports point to different, sometimes deeply nested files.

One of the usecases that inspired React Router's config-based route pattern and routes.ts was this, for example if I want to make my apps modular or feature-based, I'd use high level folders to separate features, each of these feature might export their own routes, these routes need to be imported, and for the sake of readability and consistency, we use ~ or @ symbols as relative path aliases.

Also, sometimes, we need to import variables into the routes.ts file, for example when you want to create a unique id for a route and you don't want to duplicate code and future-proof your app, this too, would be imported using an aliased path.

These use-cases aren't currently handled correctly when the routes.ts is evaluated and executed.

Please checkout the #14090 and see the bug IRL

Reproduction

  1. Clone remix-run/react-router
  2. Checkout akamfoad:routes-path-alias-issue branch
  3. Run pnpm i
  4. cd playground/framework-spa
  5. Run pnpm run dev
  6. You'll immediately get an error that routes.ts is invalid

System Info

N/A

Used Package Manager

pnpm

Expected Behavior

For the app to work seamlessly regardless of usage of import aliases.

Actual Behavior

Error: Route config in "routes.ts" is invalid.

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