Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@onmax
Copy link
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

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

pkg-pr-new bot commented Dec 10, 2025

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

commit: 6ca0336

@atinux
Copy link
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