Skip to content

Commit cd63ba4

Browse files
author
Nowell Strite
committed
#12440 introduced a fix for tsconfig, however, it broke non-JS routes (like .mdx)
When we have a file `./app/routes/test/index.mdx` which is a route we get the following error: ``` .react-router/types/app/routes/test/+types/index.ts:10:29 - error TS2307: Cannot find module ../index.js or its corresponding type declarations. 10 type Module = typeof import("../index.js") ~~~~~~~~~~~~~ ```
1 parent 5c8ccd0 commit cd63ba4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/react-router-dev/typegen/generate.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,20 @@ function getRouteAnnotations({
322322

323323
function relativeImportSource(from: string, to: string) {
324324
let path = Path.relative(Path.dirname(from), to);
325+
326+
let extension = Path.extname(path);
327+
325328
// no extension
326329
path = Path.join(Path.dirname(path), Pathe.filename(path));
327330
if (!path.startsWith("../")) path = "./" + path;
328331

329-
return path + ".js";
332+
// In typescript, we want to support "moduleResolution": "nodenext" as well as not having "allowImportingTsExtensions": true,
333+
// so we normalize all JS like files to `.js`, but allow other extensions such as `.mdx` and others that might be used as routes.
334+
if (!extension || /\.(js|ts)x?$/.test(extension)) {
335+
extension = ".js";
336+
}
337+
338+
return path + extension;
330339
}
331340

332341
function rootDirsPath(ctx: Context, typesPath: string): string {

0 commit comments

Comments
 (0)