-
Notifications
You must be signed in to change notification settings - Fork 108
Wrangler configuration is incorrectly generated #813
Description
I'm trying to make a demo project with Nuxt Hub and Cloudflare D1. According to the documentation, Nuxt Hub should auto generate a wrangler configuration, but that's already where things went south.
The first issue was that that the generated wrangler configuration was somehow not available to the wrangler CLI. For example pnpx wrangler --config .output/server/wrangler.json d1 migrations apply DB would fail, because it could not find a config, even though there is one in .output/server/wrangler.json. There is also a .wrangler directory in my project root, which has a file that points to the config in the .output directory.
$ pnpx wrangler d1 migrations apply DB
⛅️ wrangler 4.61.1
───────────────────
Resource location: local
Use --remote if you want to access the remote instance.
✘ [ERROR] No configuration file found. Create a wrangler.jsonc file to define your D1 database.
For now, the workaround is to set --config .output/server/wrangler.json when using wrangler.
The second issue was that there were 2 bindings in the generated .output/server/wrangler.json with the same name. This was somehow solved by creating a new D1 database with wrangler and updating the Nuxt config.
As if that wasn't enough, even though migrations_dir is correct in.output/server/wrangler.json, wrangler is looking for migrations in .output/server/.output/server/db/migrations. The actual migration files are in .output/server/db/migrations/sqlite.
{
"compatibility_date": "2025-07-15",
"compatibility_flags": [
"nodejs_compat",
"no_nodejs_compat_v2"
],
"d1_databases": [
{
"binding": "DB",
"database_id": "redacted",
"migrations_table": "_hub_migrations",
"migrations_dir": ".output/server/db/migrations/"
}
],
"main": "index.mjs",
"assets": {
"binding": "ASSETS",
"directory": "../public"
},
"name": "br0kenpixel-sampletodo"
}
$ pnpx wrangler --config .output/server/wrangler.json d1 migrations apply DB
⛅️ wrangler 4.61.1
───────────────────
Resource location: local
Use --remote if you want to access the remote instance.
▲ [WARNING] No migrations folder found.
✘ [ERROR] No migrations present at /workspaces/sampletodo/.output/server/.output/server/db/migrations.
Setting migrationsDirs to ["server/db/migrations/sqlite"] does not change migrations_dir in wrangler.json. Additionally, using pnpx nuxt db migrate instead of wrangler, will result in the following error:
ℹ Ensuring database migrations are available... 2:07:46 PM
ℹ Applying database migrations... 2:07:49 PM
ℹ Database: sqlite with d1 driver 2:07:49 PM
ERROR Failed to create migrations table nuxt:hub 2:07:50 PM
D1 HTTP error: {"success":false,"errors":[{"code":10000,"message":"POST method not allowed for the api_token authentication scheme"}]}
Not sure if this is a separate issue or related. My .env has the following variables defined:
NUXT_HUB_CLOUDFLARE_ACCOUNT_IDNUXT_HUB_CLOUDFLARE_DATABASE_IDNUXT_HUB_CLOUDFLARE_API_TOKEN(permissions: D1->Edit, Workers Scripts->Edit)
I tried global tokens as well, as I'm not sure if this is a permission issue or what, but I got the same error.
Nuxt Config
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2025-07-15',
devtools: { enabled: true },
nitro: { preset: 'cloudflare-module' },
modules: ['@nuxthub/core'],
hub: {
db: {
dialect: "sqlite",
driver: "d1",
connection: { databaseId: "redacted", database: "DB" },
migrationsDirs: ["server/db/migrations/sqlite"]
}
}
})Packages
```json
{
"name": "sampletodo",
"type": "module",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"dependencies": {
"@libsql/client": "^0.17.0",
"@nuxthub/core": "0.10.6",
"drizzle-kit": "^0.31.8",
"drizzle-orm": "^0.45.1",
"nuxt": "^4.3.0",
"typescript": "^5.9.3",
"vue": "^3.5.27",
"vue-router": "^4.6.4"
}
}
</details>