Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/c3-nuxt-pin-h3-v1.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 5 additions & 2 deletions packages/create-cloudflare/templates/nuxt/pages/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
7 changes: 5 additions & 2 deletions packages/create-cloudflare/templates/nuxt/workers/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
}

await installPackages(packages, {
Expand Down
Loading