You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MySQL void/db crashes in workerd dev: mysql2 imported by absolute path bypasses the dep optimizer #410
With the MySQL dialect, void/db crashes under vp dev (the workerd runtime) with:
ReferenceError: require is not defined
at runInRunnerObject (workers/runner-worker/index.js)
Postgres is not affected.
Cause
The virtual void/db module imports mysql2 by absolute file path (packages/void/src/plugin-drizzle.ts):
constmysql2Resolved=fileURLToPath(import.meta.resolve('mysql2'));// line 19// ...import{createPool}from${JSON.stringify(mysql2Resolved)};// line 159
mysql2/index.js is CommonJS only. Vite redirects only bare specifiers to prebundled deps (tryOptimizedResolve). An absolute path skips the dep optimizer, so workerd gets the raw CommonJS file. This happens whether void is installed or workspace-linked, because the resolved path is always under node_modules.
Adding optimizeDeps.include: ['void > mysql2', 'void > mysql2/promise'] doesn't help. Both get prebundled, but the virtual module still imports the unconverted file.
Postgres works because its virtual module imports bare "pg" (line 201), which gets discovered and prebundled. Later import('pg') calls from Void's runtime then reuse that copy.
Other places that dynamically import mysql2/promise from Void's dist and are probably affected too:
runtime/better-auth-mysql.ts
runtime/migration-handler-mysql.ts
Reproduction
Copy playground/pg-test, switch it to database: 'mysql' with a mysqlTable schema, and set DATABASE_URL in .env.
Run vp dev and request a route that runs db.select().from(users).
The response is 500 ReferenceError: require is not defined. With the pg dialect, the same app gets as far as a connection error.
Suggested fix
Emit import { createPool } from "mysql2" in dev, and map it to mysql2Resolved only at build time, as already done for pg.
Activity