Skip to content

fix(create-cloudflare): pin h3 to ^1 in the Nuxt template so Cloudflare bindings work in dev with pnpm#14613

Open
lucasmzz wants to merge 2 commits into
cloudflare:mainfrom
lucasmzz:c3-nuxt-pin-h3-v1
Open

fix(create-cloudflare): pin h3 to ^1 in the Nuxt template so Cloudflare bindings work in dev with pnpm#14613
lucasmzz wants to merge 2 commits into
cloudflare:mainfrom
lucasmzz:c3-nuxt-pin-h3-v1

Conversation

@lucasmzz

@lucasmzz lucasmzz commented Jul 8, 2026

Copy link
Copy Markdown

Hotfix for fixing a regression in the Nuxt (Workers) template for pnpm users — no existing issue filed. Upstream PR to be opened to nitro-cloudflare-dev for fixing the root cause.

Problem

Scaffolding a project with pnpm create cloudflare@latest → Nuxt currently produces an app where event.context.cloudflare is
undefined in every server route during nuxt dev, so D1/KV/R2 bindings are unreachable in local development:

// server/api/hello.ts
export default defineEventHandler(async (event) => {
  const { DB } = event.context.cloudflare.env;
  // TypeError: Cannot read properties of undefined (reading 'env')

Root cause

The template's configure step installs a bare h3 for pnpm users (so the H3EventContext augmentation in the shipped env.d.ts
can resolve h3 under pnpm's isolated, non-hoisting node_modules layout). h3's latest npm dist-tag now points at the 2.x release
candidates (2.0.1-rc.23 at the time of writing; the v1 line lives under the 1x tag), so this installs h3@2.0.1-rc.x as a direct
devDependency while Nuxt 4 / nitropack 2.x run on h3@^1.15.11.

With two h3 majors installed, Nitro's auto-import layer resolves the bare h3 specifier from the project root (v2), while the server
app itself runs on nitropack's nested v1. The generated dev bundle (.nuxt/dev/index.mjs) imports from both copies. The
nitro-cloudflare-dev request hook then calls h3 v2's getRequestURL(event) on an h3 v1 event, which throws TypeError: Cannot read properties of undefined (reading 'url') before it assigns event.context.cloudflare. Nitro swallows request-hook errors
(callHook("request", event).catch(captureError)), so the request proceeds without bindings and the user's route crashes instead.

Fix

Install h3@^1, matching the h3 major that nitropack depends on. Pinning (rather than dropping the pnpm-only install) is deliberate:
without a root-level h3, the declare module "h3" augmentation in env.d.ts no longer resolves under pnpm, and
event.context.cloudflare loses its types — which is why the template installs h3 in the first place.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows: scaffolded a Nuxt project with pnpm, confirmed
      the generated package.json gets "h3": "^1.15.11", the dev bundle references only h3@1.15.11, and a server route reading
      event.context.cloudflare.env (D1 query) returns results in nuxt dev. Also confirmed event.context.cloudflare typing still
      resolves.
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this restores documented behavior of the C3 Nuxt template; no user-facing API change.

Two small notes:

  • The compare link may show the branch as lucasmzz:workers-sdk:c3-nuxt-pin-h3-v1 depending on how GitHub renders fork branches —
    either way, the "Create pull request" button from the link in your push output
    (https://github.com/lucasmzz/workers-sdk/pull/new/c3-nuxt-pin-h3-v1) targets cloudflare/workers-sdk main by default.
  • Their contributing guide asks that non-trivial changes start with an issue; this is a one-line dependency pin fixing a regression,
    so the PR itself serving as the discussion is reasonable — but if you'd rather be safe, you can file a short bug issue first and swap
    its number into the "Fixes #" line.

Open in Devin Review

@lucasmzz lucasmzz requested a review from workers-devprod as a code owner July 8, 2026 21:38
@changeset-bot

changeset-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 92cf49f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod workers-devprod requested review from a team and jamesopstad and removed request for a team July 8, 2026 21:38
@workers-devprod

workers-devprod commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

devin-ai-integration[bot]

This comment was marked as resolved.

@jamesopstad jamesopstad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jul 9, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14613

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14613

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14613

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14613

miniflare

npm i https://pkg.pr.new/miniflare@14613

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14613

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14613

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14613

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14613

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14613

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14613

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14613

wrangler

npm i https://pkg.pr.new/wrangler@14613

commit: 92cf49f

@jamesopstad

Copy link
Copy Markdown
Contributor

I just tried out the prerelease and I see v2.0.1-rc.23 of h3 in the devDependencies. What steps did you take to verify the fix?

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

Labels

None yet

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

3 participants