Skip to content

[cloudflare] Implicit nodejs_compat is not detected when deployConfig is false #4649

Closed

Description

@Perdolique

Environment

  • Nuxt 4.5.2
  • Nitro 2.13.4
  • Wrangler 4.131.1
  • cloudflare_module preset
  • Wrangler compatibility date 2026-09-13

Describe the bug

Cloudflare enables Node.js compatibility by default for compatibility dates on or after 2026-08-04. Nitro 2.13.4 does not detect this implicit compatibility when cloudflare.deployConfig is false and the user's Wrangler config does not contain an explicit nodejs_compat flag.

enableNodeCompat() currently enables the Node-compatible build only when the Wrangler config contains nodejs_compat/nodejs_compat_v2, or when deployConfig is truthy:

if (
  userCompatibilityFlags.has("nodejs_compat") ||
  userCompatibilityFlags.has("nodejs_compat_v2") ||
  nitro.options.cloudflare.deployConfig
) {
  nitro.options.cloudflare.nodeCompat = true
}

With a recent compatibility date and deployConfig: false, Nitro therefore builds node:crypto imports against the unenv implementation instead of preserving native Workers imports. The deployed Worker then fails at runtime:

[unenv] crypto.createHash is not implemented yet!

This affected both an OAuth start route and email registration in our application because both use createHash.

Reproduction

Use this Nuxt config:

export default defineNuxtConfig({
  nitro: {
    preset: "cloudflare_module",
    cloudflare: {
      deployConfig: false,
    },
  },
})

Use this Wrangler config, without an explicit compatibility flag:

{
  "compatibility_date": "2026-09-13"
}

Import and call a supported Node API from server code:

import { createHash } from "node:crypto"

export default defineEventHandler(() => {
  return createHash("sha256").update("test").digest("hex")
})

Build and deploy the Worker. The request fails with the unenv error above.

Adding this to wrangler.jsonc before building makes Nitro preserve the native import and fixes the runtime failure:

{
  "compatibility_flags": ["nodejs_compat"]
}

Wrangler 4.131.1 accepts this redundant explicit flag, but it should not be required for Nitro to select the correct build behavior.

Expected behavior

Nitro should treat Node.js compatibility as enabled when the resolved Wrangler compatibility date is on or after 2026-08-04, even when deployConfig is false and no explicit compatibility flag is present.

Additional context

This is related to #4527, but it is a different failure mode. That issue covers Nitro adding a redundant flag to generated Wrangler config. This issue covers Nitro failing to enable its Node-compatible build when the runtime feature is implicit and Nitro does not generate the deploy config.

The real-world workaround and a regression test are in Perdolique/perd#767.

Activity

  1. pi0x commented on Sep 25, 2026

    @pi0x
    Contributor

    Fixed by #4667 on the v2 branch: Nitro now enables Node.js compat automatically for compatibility dates from 2026-08-04, even with deployConfig: false. It will ship in the next nitropack 2.x release (after 2.13.4).

    Triaged with AI assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions