Title: MySQL void/db crashes in workerd dev: mysql2 imported by absolute path bypasses the dep optimizer · Issue #410 · voidzero-dev/void · GitHub
Open Graph Title: MySQL void/db crashes in workerd dev: mysql2 imported by absolute path bypasses the dep optimizer · Issue #410 · voidzero-dev/void
X Title: MySQL void/db crashes in workerd dev: mysql2 imported by absolute path bypasses the dep optimizer · Issue #410 · voidzero-dev/void
Description: Summary 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 mod...
Open Graph Description: Summary 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...
X Description: Summary 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...
Opengraph URL: https://github.com/voidzero-dev/void/issues/410
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MySQL void/db crashes in workerd dev: mysql2 imported by absolute path bypasses the dep optimizer","articleBody":"## Summary\n\nWith the MySQL dialect, `void/db` crashes under `vp dev` (the workerd runtime) with:\n\n```\nReferenceError: require is not defined\n at runInRunnerObject (workers/runner-worker/index.js)\n```\n\nPostgres is not affected.\n\n## Cause\n\nThe virtual `void/db` module imports `mysql2` by absolute file path (`packages/void/src/plugin-drizzle.ts`):\n\n```ts\nconst mysql2Resolved = fileURLToPath(import.meta.resolve('mysql2')); // line 19\n// ...\nimport { createPool } from ${JSON.stringify(mysql2Resolved)}; // line 159\n```\n\n`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`.\n\nAdding `optimizeDeps.include: ['void > mysql2', 'void > mysql2/promise']` doesn't help. Both get prebundled, but the virtual module still imports the unconverted file.\n\nPostgres 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.\n\nOther places that dynamically import `mysql2/promise` from Void's dist and are probably affected too:\n- `runtime/better-auth-mysql.ts`\n- `runtime/migration-handler-mysql.ts`\n\n## Reproduction\n\n1. Copy `playground/pg-test`, switch it to `database: 'mysql'` with a `mysqlTable` schema, and set `DATABASE_URL` in `.env`.\n2. Run `vp dev` and request a route that runs `db.select().from(users)`.\n3. The response is 500 `ReferenceError: require is not defined`. With the pg dialect, the same app gets as far as a connection error.\n\n## Suggested fix\n\n- Emit `import { createPool } from \"mysql2\"` in dev, and map it to `mysql2Resolved` only at build time, as already done for `pg`.\n- Add `void > mysql2` and `void > mysql2/promise` to the workerd `optimizeDeps.include` list from #407.\n- Cover a MySQL `void/db` route in dev, either in packed-consumer or in an integration test.\n\nFound while reviewing #407 (its description mentions mysql2 as a possible case).\n","author":{"url":"https://github.com/Brooooooklyn","@type":"Person","name":"Brooooooklyn"},"datePublished":"2026-10-12T10:11:05Z","url":"https://github.com/voidzero-dev/void/issues/410"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:dde5d8a9-3d38-e8ec-1412-a2c530ef935d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C278:321782:50E148:6E5EA7:6AFBA032 |
| html-safe-nonce | a4b797d6a7f9a1651e83b7a09e094389a2eccd7ba5b0bdacb19f623d359bbddb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjc4OjMyMTc4Mjo1MEUxNDg6NkU1RUE3OjZBRkJBMDMyIiwidmlzaXRvcl9pZCI6Ijg3NjIwNDQyNzEzMzE4NzY5MTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e492ae404ce12004b8e412f712032161e4d8804522dba95a7c16412d3144c2c0 |
| hovercard-subject-tag | issue:5811985004 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/voidzero-dev/void/410/issue_layout |
| twitter:image | https://opengraph.githubassets.com/76fa61308a43a3bdfca6a7a3d13d39af5643adfd75bd37beefa767f7377b1697/voidzero-dev/void/issues/410 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/76fa61308a43a3bdfca6a7a3d13d39af5643adfd75bd37beefa767f7377b1697/voidzero-dev/void/issues/410 |
| og:image:alt | Summary 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Brooooooklyn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3cefd19a936819d82cfb5279d50fb56fe79cb9ec30f0f807e04e89b0c58ffae1 |
| turbo-cache-control | no-preview |
| go-import | github.com/voidzero-dev/void git https://github.com/voidzero-dev/void.git |
| octolytics-dimension-user_id | 149750581 |
| octolytics-dimension-user_login | voidzero-dev |
| octolytics-dimension-repository_id | 1164437080 |
| octolytics-dimension-repository_nwo | voidzero-dev/void |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1164437080 |
| octolytics-dimension-repository_network_root_nwo | voidzero-dev/void |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 606800bdb1b81d125fc845bdcc262c9fe063fc8f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width