Skip to content

fix(db): lazy D1/Hyperdrive binding access#694

Merged
atinux merged 1 commit intonuxt-hub:mainfrom
onmax:fix/d1-lazy-binding
Dec 10, 2025
Merged

fix(db): lazy D1/Hyperdrive binding access#694
atinux merged 1 commit intonuxt-hub:mainfrom
onmax:fix/d1-lazy-binding

Conversation

@onmax
Copy link
Copy Markdown
Contributor

@onmax onmax commented Dec 10, 2025

Fixes #692

Problem: D1/Hyperdrive bindings accessed at module load time. On CF Workers, bindings only available in request context.

Fix: Lazy Proxy - binding accessed only when querying.

Repro

# Clone and reproduce bug
git clone https://github.com/onmax/nuxthub-d1-repro.git && cd nuxthub-d1-repro
pnpm install && NITRO_PRESET=cloudflare-module pnpm build
cat node_modules/.cache/nuxt/.nuxt/hub/db.mjs
# Shows: const binding = ... (accessed at module load)

# Verify fix
git checkout with-fix
pnpm install && NITRO_PRESET=cloudflare-module pnpm build
cat node_modules/.cache/nuxt/.nuxt/hub/db.mjs
# Shows: Proxy with lazy getDb()

Repro diff

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 10, 2025

@onmax is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Dec 10, 2025

npm i https://pkg.pr.new/@nuxthub/core@694

commit: 6ca0336

@atinux
Copy link
Copy Markdown
Contributor

atinux commented Dec 10, 2025

This is actually a very elegant solution thank you @onmax

@atinux atinux merged commit 0087dfa into nuxt-hub:main Dec 10, 2025
7 of 9 checks passed
@onmax onmax deleted the fix/d1-lazy-binding branch December 10, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1] D1 binding accessed at module load time, breaks Cloudflare Workers deploy

2 participants