Skip to content

SvelteKit: a third-party package's void/db gets the D1 client in dev, and pg/MySQL builds inline workerd-only dependency code #420

Closed

Description

@Brooooooklyn

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 client instead. Using it throws:

db: Missing Cloudflare binding 'DB'. This app connects through HYPERDRIVE or DATABASE_URL, but its server
bundle loaded the D1 client. In Nuxt or Analog, add 'void/nitro' to the Nitro modules.

The message also points SvelteKit users to Nuxt and Analog, which does not help them.

app route ── import 'void/db' ──> Vite SSR graph ──> generated pg client      (ok)
xa-db-lib ── import 'void/db' ──> Node (package is external) ──> dist/runtime/db.mjs (D1 client)

b. pg/MySQL builds inline workerd-only dependency code (risk)

For 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.

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.

Repro

a.

  1. SvelteKit app, void.config.ts with database: 'pg', a pg schema, and DATABASE_URL in .env.
  2. Add node_modules/xa-db-lib/index.js:
    import { db } from 'void/db';
    export function libDb() {
      try { return { execute: typeof db.execute }; } catch (e) { return { error: String(e) }; }
    }
  3. Add src/routes/api/lib/+server.ts, which returns { app: typeof db.execute, lib: libDb() }.
  4. vp dev, request /api/lib:
    {"app":{"execute":"function","run":"undefined"},"lib":{"error":"Error: db: Missing Cloudflare binding 'DB'. ..."}}

b. Add a dependency whose workerd export statically imports cloudflare:sockets, import it from server code in a SvelteKit pg app, and run vp build.

Cause

  • 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.
  • b. packages/void/src/plugin-framework.ts:310-330 (void:sveltekit-worker-build): noExternal: true at :325, conditions at :322, platform: 'neutral' at :329.

Suggested fix

  • 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.
  • 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).

Evidence

🤖 Generated with Claude Code

https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH

Activity

  1. added 5 commits that reference this issue on Oct 14, 2026
    4abec3c
    cdf8874
    85657c6
    39d8dab
    afe1470
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions