Skip to content

Cloudflare dev preset leaks wrangler into generated NitroRuntimeConfig type #4148

@johannschopplich

Description

@johannschopplich

Environment

  • Operating System: macOS
  • Node Version: v22
  • Nitro Version: nightly (3.x)
  • Package Manager: pnpm
  • Preset: cloudflare_module

Reproduction

  1. Create a Nitro project with preset: 'cloudflare_module' and a custom runtimeConfig
  2. Run nitro dev
  3. Stop the dev server
  4. Run tsc --noEmit

Describe the bug

The Cloudflare dev preset (src/presets/cloudflare/dev.ts) injects a wrangler key into runtimeConfig at module installation time to share Miniflare configuration (config path, persist dir, environment) with the runtime plugin.

However, this internal key is not filtered out during type generation in src/build/types.ts. The existing filter only excludes app and nitro:

Object.entries(nitro.options.runtimeConfig).filter(
  ([key]) => !["app", "nitro"].includes(key)
)

This causes wrangler to appear in the generated NitroRuntimeConfig interface (node_modules/.nitro/types/nitro-config.d.ts):

interface NitroRuntimeConfig {
  // ... user-defined keys ...

  wrangler: {
    configPath: string,
    persistDir: string,
    environment: any,
  },
}

Which produces a type error in nitro.config.ts because wrangler is a required property that the user never defined.

The fix is straightforward: add "wrangler" to the exclusion list in src/build/types.ts alongside "app" and "nitro". I'll open a PR with the fix.

Additional context

Running nitro prepare alone does not trigger the issue because the Cloudflare dev module only runs during nitro dev. But once the dev server has run, the generated types persist in node_modules/.nitro/types/nitro-config.d.ts and cause tsc to fail.

Logs

nitro.config.ts(23,3): error TS2741: Property 'wrangler' is missing in type '{ api: { key: string; }; paddle: { apiKey: string; apiKeySandbox: string; webhookSecret: string; webhookSecretSandbox: string; }; magicLink: { secret: string; }; resend: { apiKey: string; from: string; }; }' but required in type 'NitroRuntimeConfig'.

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