NuxtN
Nuxt9mo ago
3 replies
hackal

Nuxt + Cloudflare Pages + Cloudflare Environments + Wrangler.json

Hi,

I'm having issue with deploying to cloudflare pages. How can I specify which environment I use from wrangler.json?

My wrangler json
/**
 * For more details on how to configure Wrangler, refer to:
 * https://developers.cloudflare.com/workers/wrangler/configuration/
 */
{
    "$schema": "node_modules/wrangler/config-schema.json",
    "name": "app-prod-us-*****",
    "main": "./.output/server/index.mjs",
    "compatibility_date": "2025-04-24",
    "assets": {
        "binding": "ASSETS",
        "directory": "./.output/public/"
    },
    "observability": {
        "enabled": true
    },
    "routes": [
        {
            "pattern": "app.*****.com",
            "custom_domain": true
        }
    ],
    "vars": {
        "NUXT_PUBLIC_BASE_URL": "https://us.api.*****.com",
        "NUXT_PUBLIC_COOKIE_DOMAIN": ".*****.com",
        "NUXT_PUBLIC_ENV": "production",
        "NUXT_PUBLIC_WS_BASE_URL": "wss://us.api.*****.com"
    },
    "env": {
        "prod-eu": {
            "routes": [
                {
                    "pattern": "eu.app.*****.com",
                    "custom_domain": true
                }
            ],
            "vars": {
                "NUXT_PUBLIC_BASE_URL": "https://eu.api.*****.com",
                "NUXT_PUBLIC_COOKIE_DOMAIN": ".*****.com",
                "NUXT_PUBLIC_ENV": "production",
                "NUXT_PUBLIC_WS_BASE_URL": "wss://eu.api.*****.com"
            }
        },
        "staging-us": {
            "routes": [
                {
                    "pattern": "develop.app.*****.com",
                    "custom_domain": true
                }
            ],
            "vars": {
                "NUXT_PUBLIC_BASE_URL": "https://staging.us.api.*****.com",
                "NUXT_PUBLIC_COOKIE_DOMAIN": ".*****.com",
                "NUXT_PUBLIC_ENV": "staging",
                "NUXT_PUBLIC_WS_BASE_URL": "wss://staging.us.api.*****.com"
            }
        },
        "staging-eu": {
            "routes": [
                {
                    "pattern": "staging.eu.app.*****.com",
                    "custom_domain": true
                }
            ]
        }
    }
}


My deploy command (I test locally)

nuxt build && wrangler deploy


I get this error

- Redirected configurations cannot include environments but the following have been found:
        - prod-eu
        - staging-us
        - staging-eu
  
  
      Such configurations are generated by tools, meaning that one of the tools
      your application is using is generating the incorrect configuration.
      Report this issue to the tool's author so that this can be fixed there.
    - You have specified the environment "staging-us", but are using a redirected configuration,
  produced by a build tool such as Vite.
      You need to set the environment in your build tool, rather than via Wrangler.
      For example, if you are using Vite, refer to these docs:
  https://developers.cloudflare.com/workers/vite-plugin/reference/cloudflare-environments/


https://nuxt.com/deploy/cloudflare and https://nitro.build/deploy/providers/cloudflare have no mentions of environemnt except for --env flag which can be used for specifying enviromnent for the wrangler deploy command.

Adding that flag makes no difference.
Nuxt
Deploy your Nuxt Application to Cloudflare infrastructure.
Deploy Nuxt to Cloudflare
Deploy Nitro apps to Cloudflare.
Cloudflare - Nitro
Was this page helpful?