Skip to content

Commit d0a24e6

Browse files
yyx990803claude
andcommitted
fix: resolve pg from void deps during build for PG projects
The virtual:void-db module imports pg as a bare specifier, but pg is a dependency of void, not the user project. Rolldown cannot resolve it during vite build. Add a resolveId hook that resolves pg to void own copy during build. Dev mode is unaffected (Vite SSR dep optimizer handles the bare import via node_modules traversal). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d2b9d29 commit d0a24e6

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎packages/void/src/plugin-drizzle.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const drizzleD1Resolved = fileURLToPath(import.meta.resolve("drizzle-orm/d1"));
1212
const drizzleOrmResolved = fileURLToPath(import.meta.resolve("drizzle-orm"));
1313
const envModuleResolved = fileURLToPath(import.meta.resolve("void/_env"));
1414
const drizzleNodePgResolved = fileURLToPath(import.meta.resolve("drizzle-orm/node-postgres"));
15+
const pgResolved = fileURLToPath(import.meta.resolve("pg"));
1516

1617
const VIRTUAL_DB_ID = "\0virtual:void-db";
1718

@@ -40,11 +41,14 @@ export function drizzlePlugin(
4041
generateDbDts(outDir, schema, dialect);
4142
}
4243

44+
let isBuild = false;
45+
4346
return {
4447
name: "void:drizzle",
4548
enforce: "pre",
4649

47-
config() {
50+
config(_, env) {
51+
isBuild = env.command === "build";
4852
if (!schema) return;
4953

5054
return {
@@ -57,8 +61,14 @@ export function drizzlePlugin(
5761
},
5862

5963
resolveId: {
60-
filter: { id: /^(void\/db|@schema)/ },
64+
filter: { id: /^(void\/db|@schema|pg$)/ },
6165
handler(id, importer) {
66+
// Resolve pg from void's own deps during build so PG projects
67+
// don't need pg as a direct dependency.
68+
if (id === "pg" && isBuild && dialect === "postgresql" && importer === VIRTUAL_DB_ID) {
69+
return pgResolved;
70+
}
71+
6272
// Only intercept void/db in server/worker environments (not client)
6373
if (id === "void/db" && this.environment?.name !== "client") {
6474
if (!schema) return; // Fall through to the real module (stub)

0 commit comments

Comments
 (0)