Skip to content

fix(dev/typegen): Fix virtual module typegen with moduleDetection: "force" #13267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/honest-moles-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-router/dev": patch
---

Fix typegen for virtual modules when `moduleDetection` is set to `force`
24 changes: 24 additions & 0 deletions integration/typegen-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,30 @@ test.describe("typegen", () => {
expect(proc.status).toBe(0);
});

test("works with tsconfig 'moduleDetection' set to 'force'", async () => {
const cwd = await createProject({
"vite.config.ts": viteConfig,
"app/routes.ts": tsx`
import { type RouteConfig } from "@react-router/dev/routes";
export default [] satisfies RouteConfig;
`,
"app/handler.ts": tsx`
import { createRequestHandler } from "react-router";
import * as serverBuild from "virtual:react-router/server-build";
export default createRequestHandler(serverBuild);
`,
});

const tsconfig = await fse.readJson(path.join(cwd, "tsconfig.json"));
tsconfig.compilerOptions.moduleDetection = "force";
await fse.writeJson(path.join(cwd, "tsconfig.json"), tsconfig);

const proc = typecheck(cwd);
expect(proc.stdout.toString()).toBe("");
expect(proc.stderr.toString()).toBe("");
expect(proc.status).toBe(0);
});

test("dynamic import matches 'createRequestHandler' function argument type", async () => {
const cwd = await createProject({
"vite.config.ts": viteConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dev/typegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function writeAll(ctx: Context): Promise<void> {
const registerPath = Path.join(typegenDir, "+register.ts");
fs.writeFileSync(registerPath, register(ctx));

const virtualPath = Path.join(typegenDir, "+virtual.ts");
const virtualPath = Path.join(typegenDir, "+virtual.d.ts");
fs.writeFileSync(virtualPath, virtual);
}

Expand Down