Hi π
I previously opened an issue regarding multi-deployment and dev bindings. The suggested solution (using $production.nitro.preset: 'cloudflare_module') works well and solved that use case β thanks for that.
However, I ran into another issue when trying to configure Cloudflare resources entirely from nuxt.config.ts (it works fine in production but throws an error in development).
Environment
- Nuxt: 4.4.2
- @nuxthub/core: 0.10.7
- Nitro: 2.13.1
Working setup (with wrangler.jsonc)
When bindings are defined in wrangler.jsonc, everything works correctly in both dev and production.
export default defineNuxtConfig({
nitro: {
preset: 'cloudflare_module',
cloudflare: {
deployConfig: true,
nodeCompat: true
}
},
hub: {
db: 'sqlite',
blob: true,
cache: true,
kv: true
}
})
Dev server starts normally and migrations run correctly.
Non-working setup (bindings defined in nuxt.config.ts)
If I try to define the bindings through nitro.cloudflare.wrangler and hub configuration instead of wrangler.jsonc, dev mode fails.
export default defineNuxtConfig({
nitro: {
preset: 'cloudflare_module',
cloudflare: {
deployConfig: true,
nodeCompat: true,
wrangler: {
name: process.env.NAME,
observability: { enabled: true },
}
}
},
hub: {
db: {
dialect: 'sqlite',
driver: 'd1',
connection: { databaseId: process.env.DATABASE_ID }
},
kv: {
driver: 'cloudflare-kv-binding',
namespaceId: process.env.KV_ID
},
cache: {
driver: 'cloudflare-kv-binding',
namespaceId: process.env.CACHE_ID
},
blob: {
driver: 'cloudflare-r2',
binding: 'BLOB',
bucketName: process.env.BLOB_NAME
}
}
})
Error in dev
Dev server starts but migrations fail:
[nuxt:hub] ERROR Failed to create migrations table
[nuxt-hub] DB binding not found
Interestingly, the logs show that nuxt-hub correctly identifies the desired driver:
hub:db using sqlite database with d1 driver
hub:kv using cloudflare-kv-binding driver
hub:cache using cloudflare-kv-binding driver
hub:blob using cloudflare-r2 driver
However, even though the database is appropriately configured in the hub object, the Cloudflare dev emulator (Miniflare) does not seem to provide the DB binding globally.
Note on drivers: If I use the shorthand db: 'sqlite', it works only because it falls back to the libsql driver locally (creating a file in .data/db), which avoids the binding requirement but diverges from the intended "Cloudflare-emulated" setup. Replacing it with an explicit driver: 'd1' configuration consistently reveals the missing binding.
Expected behavior
If bindings are defined via nitro.cloudflare.wrangler / hub configuration, they should also be injected into the local development context by Nitro/Miniflare, without requiring a physical wrangler.jsonc file on disk.
This would allow keeping all infrastructure configuration inside nuxt.config.ts, which is especially useful for:
- Multi-deployment setups (switching IDs via env vars in
nuxt.config.ts)
- CI/CD driven configuration
- Avoiding project-specific
wrangler.jsonc files
Question
Is this a known limitation where the local emulator specifically requires a physical config file, or should Nitro / NuxtHub be syncing these code-defined bindings to the emulator environment?
Thanks!
Hi π
I previously opened an issue regarding multi-deployment and dev bindings. The suggested solution (using
$production.nitro.preset: 'cloudflare_module') works well and solved that use case β thanks for that.However, I ran into another issue when trying to configure Cloudflare resources entirely from
nuxt.config.ts(it works fine in production but throws an error in development).Environment
Working setup (with
wrangler.jsonc)When bindings are defined in
wrangler.jsonc, everything works correctly in both dev and production.{ "d1_databases": [ { "binding": "DB", "database_name": "...", "database_id": "xxxx", "migrations_table": "_hub_migrations", "migrations_dir": "server/db/migrations/sqlite/" } ], "r2_buckets": [ { "binding": "BLOB", "bucket_name": "..." } ], "kv_namespaces": [ { "binding": "CACHE", "id": "xxxx" }, { "binding": "KV", "id": "xxxx" } ] }Dev server starts normally and migrations run correctly.
Non-working setup (bindings defined in
nuxt.config.ts)If I try to define the bindings through
nitro.cloudflare.wranglerand hub configuration instead ofwrangler.jsonc, dev mode fails.Error in dev
Dev server starts but migrations fail:
Interestingly, the logs show that
nuxt-hubcorrectly identifies the desired driver:However, even though the database is appropriately configured in the
hubobject, the Cloudflare dev emulator (Miniflare) does not seem to provide theDBbinding globally.Note on drivers: If I use the shorthand
db: 'sqlite', it works only because it falls back to thelibsqldriver locally (creating a file in.data/db), which avoids the binding requirement but diverges from the intended "Cloudflare-emulated" setup. Replacing it with an explicitdriver: 'd1'configuration consistently reveals the missing binding.Expected behavior
If bindings are defined via
nitro.cloudflare.wrangler/hubconfiguration, they should also be injected into the local development context by Nitro/Miniflare, without requiring a physicalwrangler.jsoncfile on disk.This would allow keeping all infrastructure configuration inside
nuxt.config.ts, which is especially useful for:nuxt.config.ts)wrangler.jsoncfilesQuestion
Is this a known limitation where the local emulator specifically requires a physical config file, or should
Nitro/NuxtHubbe syncing these code-defined bindings to the emulator environment?Thanks!