Skip to content

Commit 47c4c03

Browse files
Fix virtual module typegen with moduleDetection: "force" (#13267)
1 parent 237304d commit 47c4c03

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

.changeset/honest-moles-brush.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-router/dev": patch
3+
---
4+
5+
Fix typegen for virtual modules when `moduleDetection` is set to `force`

integration/typegen-test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,30 @@ test.describe("typegen", () => {
466466
expect(proc.status).toBe(0);
467467
});
468468

469+
test("works with tsconfig 'moduleDetection' set to 'force'", async () => {
470+
const cwd = await createProject({
471+
"vite.config.ts": viteConfig,
472+
"app/routes.ts": tsx`
473+
import { type RouteConfig } from "@react-router/dev/routes";
474+
export default [] satisfies RouteConfig;
475+
`,
476+
"app/handler.ts": tsx`
477+
import { createRequestHandler } from "react-router";
478+
import * as serverBuild from "virtual:react-router/server-build";
479+
export default createRequestHandler(serverBuild);
480+
`,
481+
});
482+
483+
const tsconfig = await fse.readJson(path.join(cwd, "tsconfig.json"));
484+
tsconfig.compilerOptions.moduleDetection = "force";
485+
await fse.writeJson(path.join(cwd, "tsconfig.json"), tsconfig);
486+
487+
const proc = typecheck(cwd);
488+
expect(proc.stdout.toString()).toBe("");
489+
expect(proc.stderr.toString()).toBe("");
490+
expect(proc.status).toBe(0);
491+
});
492+
469493
test("dynamic import matches 'createRequestHandler' function argument type", async () => {
470494
const cwd = await createProject({
471495
"vite.config.ts": viteConfig,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function writeAll(ctx: Context): Promise<void> {
8989
const registerPath = Path.join(typegenDir, "+register.ts");
9090
fs.writeFileSync(registerPath, register(ctx));
9191

92-
const virtualPath = Path.join(typegenDir, "+virtual.ts");
92+
const virtualPath = Path.join(typegenDir, "+virtual.d.ts");
9393
fs.writeFileSync(virtualPath, virtual);
9494
}
9595

0 commit comments

Comments
 (0)