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

Skip to content

Env variables not working on Cloudflare Pages #26215

@matt-clegg

Description

@matt-clegg

Environment


  • Operating System: Windows_NT
  • Node Version: v20.11.1
  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: -
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools, runtimeConfig, nitro
  • Runtime Modules: -
  • Build Modules: -

Reproduction

The reproduction is increadibly simple. Create a new Nuxt app with pnpm dlx nuxi@latest init <project-name>.

nuxt.config.ts

export default defineNuxtConfig({
    devtools: {enabled: true},

    runtimeConfig: {
        public: {
            exampleValue: "unknown"
        }
    },
    
    nitro: {
        preset: "cloudflare-pages"
    }
})

app.vue

<template>
  <div>
    <strong>Config:</strong>
    <pre>{{ config}}</pre>
  </div>
</template>

<script setup lang="ts">
const config = useRuntimeConfig();
</script>

Build the Nuxt app with nuxt build then deploy it to Cloudflare using pnpm dlx wrangler pages deploy dist/.

Describe the bug

When the Nuxt app is deployed to Cloudflare Pages using the cloudflare-pages nitro preset, environment variables aren't passed down into Nuxt. Unless I've missed a step in configuring the Nuxt app or something else in Cloudflare, I would expect the public.exampleValue to be overridden with my environment value.

The hosted Nuxt app can be found here: https://pages-env-demo-55q.pages.dev/
image

My environment variable in Cloudflare Pages are configured like so:
image

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions