Using Wrangler environments and the Nuxt template

Hi everyone, this is my first time using cloudflare so sorry if I'm missing something obvious! I've created a Nuxt project with the help of npm create cloudflare I then deployed it successfully with no changes. Now I want to setup environments so I can run a separate dev worker with a separate D1 database and then deploy them from GitLab. So I made the following changes to the wrangler file:
{
"$schema": "node_modules/wrangler/config-schema.json",
"main": "./.output/server/index.mjs",
"compatibility_date": "2025-11-01",
"name": "dialnote-prod",
"assets": {
"binding": "ASSETS",
"directory": "./.output/public/"
},
"observability": {
"enabled": true
},
"env": {
"dev": {
"name": "dialnote-dev",
"d1_databases": [
{
"binding": "db",
"database_name": "dialnote_dev",
"database_id": "removed"
}
]
},
"prod": {
"name": "dialnote-prod",
"d1_databases": [
{
"binding": "db",
"database_name": "dialnote_prod",
"database_id": "removed"
}
]
}
}
}
{
"$schema": "node_modules/wrangler/config-schema.json",
"main": "./.output/server/index.mjs",
"compatibility_date": "2025-11-01",
"name": "dialnote-prod",
"assets": {
"binding": "ASSETS",
"directory": "./.output/public/"
},
"observability": {
"enabled": true
},
"env": {
"dev": {
"name": "dialnote-dev",
"d1_databases": [
{
"binding": "db",
"database_name": "dialnote_dev",
"database_id": "removed"
}
]
},
"prod": {
"name": "dialnote-prod",
"d1_databases": [
{
"binding": "db",
"database_name": "dialnote_prod",
"database_id": "removed"
}
]
}
}
}
2 Replies
RB35
RB35OP2w ago
At first I thought I could use --env prod but then realised after trying that I can't do that because of vite generating a flattened file at build (I think). So I then changed the build command instead to this CLOUDFLARE_ENV=prod npm run build but then got this error:
21:18:00.037 - Configuration being used: ".output/server/wrangler.json"
21:18:00.037 - Original user's configuration: "wrangler.jsonc"
21:18:00.037 - Deploy configuration file: ".wrangler/deploy/config.json"
21:18:00.043
21:18:00.110 ✘ [ERROR] Processing .output/server/wrangler.json configuration:
21:18:00.110
21:18:00.110 - Redirected configurations cannot include environments but the following have been found:
21:18:00.110 - dev
21:18:00.110 - prod
21:18:00.110
21:18:00.110
21:18:00.110 Such configurations are generated by tools, meaning that one of the tools
21:18:00.110 your application is using is generating the incorrect configuration.
21:18:00.111 Report this issue to the tool's author so that this can be fixed there.
21:18:00.111
21:18:00.111
21:18:00.130
21:18:00.131 Cloudflare collects anonymous telemetry about your usage of Wrangler. Learn more at https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md
21:18:00.151 🪵 Logs were written to "/opt/buildhome/.config/.wrangler/logs/wrangler-2025-11-07_10-17-59_387.log"
21:18:00.292 Failed: error occurred while running deploy command
21:18:00.037 - Configuration being used: ".output/server/wrangler.json"
21:18:00.037 - Original user's configuration: "wrangler.jsonc"
21:18:00.037 - Deploy configuration file: ".wrangler/deploy/config.json"
21:18:00.043
21:18:00.110 ✘ [ERROR] Processing .output/server/wrangler.json configuration:
21:18:00.110
21:18:00.110 - Redirected configurations cannot include environments but the following have been found:
21:18:00.110 - dev
21:18:00.110 - prod
21:18:00.110
21:18:00.110
21:18:00.110 Such configurations are generated by tools, meaning that one of the tools
21:18:00.110 your application is using is generating the incorrect configuration.
21:18:00.111 Report this issue to the tool's author so that this can be fixed there.
21:18:00.111
21:18:00.111
21:18:00.130
21:18:00.131 Cloudflare collects anonymous telemetry about your usage of Wrangler. Learn more at https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md
21:18:00.151 🪵 Logs were written to "/opt/buildhome/.config/.wrangler/logs/wrangler-2025-11-07_10-17-59_387.log"
21:18:00.292 Failed: error occurred while running deploy command
I then tried setting the environment variable then building locally and then looked at .output/server/wrangler.json which was:
{
"compatibility_date": "2025-11-01",
"$schema": "node_modules/wrangler/config-schema.json",
"main": "index.mjs",
"name": "dialnote",
"assets": {
"binding": "ASSETS",
"directory": "..\\public"
},
"observability": {
"enabled": true
},
"env": {
"development": {
"d1_databases": [
{
"binding": "db",
"database_name": "dialnote_dev",
"database_id": "removed"
}
]
},
"production": {
"d1_databases": [
{
"binding": "db",
"database_name": "dialnote_prod",
"database_id": "removed"
}
]
}
},
"compatibility_flags": [
"nodejs_compat",
"no_nodejs_compat_v2"
]
}
{
"compatibility_date": "2025-11-01",
"$schema": "node_modules/wrangler/config-schema.json",
"main": "index.mjs",
"name": "dialnote",
"assets": {
"binding": "ASSETS",
"directory": "..\\public"
},
"observability": {
"enabled": true
},
"env": {
"development": {
"d1_databases": [
{
"binding": "db",
"database_name": "dialnote_dev",
"database_id": "removed"
}
]
},
"production": {
"d1_databases": [
{
"binding": "db",
"database_name": "dialnote_prod",
"database_id": "removed"
}
]
}
},
"compatibility_flags": [
"nodejs_compat",
"no_nodejs_compat_v2"
]
}
So it appears it's not being flattened? If more info is needed let me know, Thanks in advanced!🙂
RB35
RB35OP2w ago
After a bit more investigating I realised that the wrangler config is generated by nitro and you actually don't really need a wrangler file setup. You can specify everything within the nuxt.config.ts which allows you to use it's environment overrides. It might be easier to just make a Nuxt project then add Cloudflare in. https://nitro.build/deploy/providers/cloudflare https://nuxt.com/docs/4.x/getting-started/configuration#environment-overrides
Cloudflare - Nitro
Deploy Nitro apps to Cloudflare.
Nuxt
Configuration · Get Started with Nuxt v4
Nuxt is configured with sensible defaults to make you productive.

Did you find this page helpful?