Title: SvelteKit: a third-party package's `void/db` gets the D1 client in dev, and pg/MySQL builds inline workerd-only dependency code · Issue #420 · voidzero-dev/void · GitHub
Open Graph Title: SvelteKit: a third-party package's `void/db` gets the D1 client in dev, and pg/MySQL builds inline workerd-only dependency code · Issue #420 · voidzero-dev/void
X Title: SvelteKit: a third-party package's `void/db` gets the D1 client in dev, and pg/MySQL builds inline workerd-only dependency code · Issue #420 · voidzero-dev/void
Description: Problem a. A package that imports void/db gets the D1 client in dev In a SvelteKit app with database: 'pg' (or MySQL), the app's own void/db is the generated pg client. A package in node_modules that imports void/db gets Void's static D1...
Open Graph Description: Problem a. A package that imports void/db gets the D1 client in dev In a SvelteKit app with database: 'pg' (or MySQL), the app's own void/db is the generated pg client. A package in node_modules th...
X Description: Problem a. A package that imports void/db gets the D1 client in dev In a SvelteKit app with database: 'pg' (or MySQL), the app's own void/db is the generated pg client. A package in nod...
Opengraph URL: https://github.com/voidzero-dev/void/issues/420
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SvelteKit: a third-party package's `void/db` gets the D1 client in dev, and pg/MySQL builds inline workerd-only dependency code","articleBody":"## Problem\n\n### a. A package that imports `void/db` gets the D1 client in dev\n\nIn a SvelteKit app with `database: 'pg'` (or MySQL), the app's own `void/db` is the generated pg client. A package in `node_modules` that imports `void/db` gets Void's static D1 client instead. Using it throws:\n\n```\ndb: Missing Cloudflare binding 'DB'. This app connects through HYPERDRIVE or DATABASE_URL, but its server\nbundle loaded the D1 client. In Nuxt or Analog, add 'void/nitro' to the Nitro modules.\n```\n\nThe message also points SvelteKit users to Nuxt and Analog, which does not help them.\n\n```\napp route ── import 'void/db' ──> Vite SSR graph ──> generated pg client (ok)\nxa-db-lib ── import 'void/db' ──> Node (package is external) ──> dist/runtime/db.mjs (D1 client)\n```\n\n### b. pg/MySQL builds inline workerd-only dependency code (risk)\n\nFor SvelteKit pg/MySQL builds, #413 builds Kit's `ssr` environment for workerd: `resolve.noExternal: true`, `workerd`/`worker` conditions and neutral output. Kit's analyse step then loads that output in Node. A dependency whose `workerd` build statically imports a `cloudflare:` module would now be bundled into that output, and Node cannot load it (`ERR_UNSUPPORTED_ESM_URL_SCHEME`). Before #413 such a dependency stayed external, and Node loaded its Node build.\n\n**This was seen only with a synthetic package** (`exports: { workerd: './cf.js', default: './node.js' }`, where `cf.js` has `import { connect } from 'cloudflare:sockets'`). The server entry then started with `import \"cloudflare:sockets\"`. No real package has been shown to break. `pg` is fine: `pg-cloudflare` imports `cloudflare:sockets` lazily.\n\n## Repro\n\na.\n1. SvelteKit app, `void.config.ts` with `database: 'pg'`, a pg schema, and `DATABASE_URL` in `.env`.\n2. Add `node_modules/xa-db-lib/index.js`:\n ```js\n import { db } from 'void/db';\n export function libDb() {\n try { return { execute: typeof db.execute }; } catch (e) { return { error: String(e) }; }\n }\n ```\n3. Add `src/routes/api/lib/+server.ts`, which returns `{ app: typeof db.execute, lib: libDb() }`.\n4. `vp dev`, request `/api/lib`:\n ```json\n {\"app\":{\"execute\":\"function\",\"run\":\"undefined\"},\"lib\":{\"error\":\"Error: db: Missing Cloudflare binding 'DB'. ...\"}}\n ```\n\nb. Add a dependency whose `workerd` export statically imports `cloudflare:sockets`, import it from server code in a SvelteKit pg app, and run `vp build`.\n\n## Cause\n\n- a. Vite's SSR graph externalizes a package that resolves into `node_modules`. Void inlines only `void` itself (`packages/void/src/plugin-framework.ts:232`, `ssr.noExternal: ['void']`). The external package's `void/db` goes to the package export `./dist/runtime/db.mjs`, the static D1 client (`packages/void/src/runtime/db.ts:59-70`). `packages/void/AGENTS.md:101` notes that such packages load their own env module copies; `void/db` has the same limit.\n- b. `packages/void/src/plugin-framework.ts:310-330` (`void:sveltekit-worker-build`): `noExternal: true` at `:325`, conditions at `:322`, `platform: 'neutral'` at `:329`.\n\n## Suggested fix\n\n- a. In SvelteKit dev, inline packages that import `void/*` (for example, find them in the dependency graph and add them to `ssr.noExternal`). At least, make the D1 client's error name the real cause for SvelteKit.\n- b. Inline only the driver chain that `void/db` needs (`void`, `drizzle-orm`, `pg`, `pg-*`, `mysql2` and their dependencies), and leave other dependencies to Kit's Node resolution. Or document the limit. Check real packages first, for example `postgres` (its `cloudflare` build).\n\n## Evidence\n\n- a. Reproduced at the head of #413 with a workspace-linked `void` (response above). #413 makes the app's own `void/db` work with an installed `void`; it does not change a third-party package's import, and it adds the Nuxt/Analog wording to the error.\n- b. Synthetic probe only, built with the head of #413. The SvelteKit build plugin is new in #413 (`bd1705f26`); before it, pg/MySQL SvelteKit Workers failed at request time instead.\n\n🤖 Generated with [Claude Code](https://claude.com/claude-code)\n\nhttps://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH\n","author":{"url":"https://github.com/Brooooooklyn","@type":"Person","name":"Brooooooklyn"},"datePublished":"2026-10-14T04:05:36Z","url":"https://github.com/voidzero-dev/void/issues/420"}
| 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:f99192e8-e715-af9b-8893-2e8317906b30 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9440:1ED5BC:2D482D:3D46E4:6AFBA150 |
| html-safe-nonce | ba4428497a218f107812a44a5a4eec3c67956c9d4308fb4310992e7ad2dba11e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDQwOjFFRDVCQzoyRDQ4MkQ6M0Q0NkU0OjZBRkJBMTUwIiwidmlzaXRvcl9pZCI6IjQzMjQwMTA0MzM1ODYxMTA4MDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | cd0a8b87c7d74016cfc7b55d1a75182b57083bf91fa4b7ce333c19d879fcbaaf |
| hovercard-subject-tag | issue:5841739219 |
| 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/420/issue_layout |
| twitter:image | https://opengraph.githubassets.com/db26a38068df2a27ac400c99ae195969779120f71b4f5b29b9d2a612443a599e/voidzero-dev/void/issues/420 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/db26a38068df2a27ac400c99ae195969779120f71b4f5b29b9d2a612443a599e/voidzero-dev/void/issues/420 |
| og:image:alt | Problem a. A package that imports void/db gets the D1 client in dev In a SvelteKit app with database: 'pg' (or MySQL), the app's own void/db is the generated pg client. A package in node_modules th... |
| 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