From ac487398279a60ae6d895fa8da7c171d4e26f1f1 Mon Sep 17 00:00:00 2001 From: Lucas Mazzutti Date: Wed, 8 Jul 2026 23:33:24 +0200 Subject: [PATCH 1/2] fix(create-cloudflare): pin h3 to ^1 in the Nuxt template for pnpm --- .changeset/c3-nuxt-pin-h3-v1.md | 9 +++++++++ packages/create-cloudflare/templates/nuxt/workers/c3.ts | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .changeset/c3-nuxt-pin-h3-v1.md diff --git a/.changeset/c3-nuxt-pin-h3-v1.md b/.changeset/c3-nuxt-pin-h3-v1.md new file mode 100644 index 0000000000..4bb8d31eae --- /dev/null +++ b/.changeset/c3-nuxt-pin-h3-v1.md @@ -0,0 +1,9 @@ +--- +"create-cloudflare": patch +--- + +Fix Cloudflare bindings being unavailable during `nuxt dev` in pnpm projects created from the Nuxt template + +The Nuxt (Workers) template explicitly installs `h3` when using pnpm, so that the `H3EventContext` type augmentation in `env.d.ts` can resolve the `h3` module under pnpm's isolated `node_modules` layout. Since h3's `latest` npm dist-tag moved to the 2.x release candidates, this installed `h3@2.0.1-rc.x` alongside the `h3@1.x` that Nuxt/Nitro run on. Nitro's auto-import layer then resolved `getRequestURL` from h3 v2, which throws when called with an h3 v1 event inside the `nitro-cloudflare-dev` request hook. Nitro swallows request-hook errors, so the hook silently failed before assigning `event.context.cloudflare`, and any server route accessing bindings crashed with "Cannot read properties of undefined (reading 'env')". + +The template now installs `h3@^1`, matching the h3 major that nitropack depends on. diff --git a/packages/create-cloudflare/templates/nuxt/workers/c3.ts b/packages/create-cloudflare/templates/nuxt/workers/c3.ts index 6d86078ef7..0113664a45 100644 --- a/packages/create-cloudflare/templates/nuxt/workers/c3.ts +++ b/packages/create-cloudflare/templates/nuxt/workers/c3.ts @@ -33,9 +33,12 @@ const configure = async () => { const packages = ["nitro-cloudflare-dev", "nitropack"]; // When using pnpm, explicitly add h3 package so the H3Event type declaration can be updated. - // Package managers other than pnpm will hoist the dependency, as will pnpm with `--shamefully-hoist` + // Package managers other than pnpm will hoist the dependency, as will pnpm with `--shamefully-hoist`. + // Pin to the h3 major used by nitropack — h3's `latest` dist-tag now points at the 2.x release + // candidates, which are incompatible with the h3 v1 runtime Nuxt/Nitro use and break + // `event.context.cloudflare` in dev. if (pm === "pnpm") { - packages.push("h3"); + packages.push("h3@^1"); } await installPackages(packages, { From 92cf49f376d781046d9280358b5c9566f6e93bb9 Mon Sep 17 00:00:00 2001 From: Lucas Mazzutti Date: Thu, 9 Jul 2026 10:12:44 +0200 Subject: [PATCH 2/2] applying same fix for Pages for consistency --- packages/create-cloudflare/templates/nuxt/pages/c3.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/create-cloudflare/templates/nuxt/pages/c3.ts b/packages/create-cloudflare/templates/nuxt/pages/c3.ts index 671d4ba639..1f88bcb3ff 100644 --- a/packages/create-cloudflare/templates/nuxt/pages/c3.ts +++ b/packages/create-cloudflare/templates/nuxt/pages/c3.ts @@ -33,9 +33,12 @@ const configure = async () => { const packages = ["nitro-cloudflare-dev"]; // When using pnpm, explicitly add h3 package so the H3Event type declaration can be updated. - // Package managers other than pnpm will hoist the dependency, as will pnpm with `--shamefully-hoist` + // Package managers other than pnpm will hoist the dependency, as will pnpm with `--shamefully-hoist`. + // Pin to the h3 major used by nitropack — h3's `latest` dist-tag now points at the 2.x release + // candidates, which are incompatible with the h3 v1 runtime Nuxt/Nitro use and break + // `event.context.cloudflare` in dev. if (pm === "pnpm") { - packages.push("h3"); + packages.push("h3@^1"); } await installPackages(packages, {