Bug: path aliases don't get correctly resovlved in routes.ts
#14090
+40
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
playground/framework-spa/app/routes.ts
to better get the idea.Try running
pnpm run dev
inplayground/framework-spa/
project.Expected Behavior
For the app to work seamlessly regardless of usage of import aliases.
Actual Behavior
Error: Route config in "routes.ts" is invalid.