fix: read version-specific h3 exports via runtime key#18
Merged
Conversation
`h3.toResponse` (v2-only) and `h3.send` (v1-only) were accessed as namespace members. When a downstream bundler (Nuxt -> Nitro -> Rollup) re-bundles dist/index.mjs, Rollup resolves those against the installed h3 and turns them into static named imports, breaking the build for the version that lacks the symbol (e.g. `"toResponse" is not exported by h3` on h3 v1). Read the symbols through a runtime key so no bundler can fold them into a static named import. Add a Rollup-based regression test that bundles dist/index.mjs against a stub h3 and asserts no missing-export warnings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
pnpm's strict node_modules layout doesn't hoist rollup (a transitive
unbuild dep) to the top level, so import('rollup') fails in CI.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
1.0.0breaks downstream Nuxt builds on h3 v1:Root cause
helper.tsaccessed the version-specific h3 symbols as namespace members —h3.toResponse(v2-only) andh3.send(v1-only). Our owndistkeeps those as runtime member access, but when a downstream bundler (Nuxt → Nitro → Rollup) re-bundlesdist/index.mjs, Rollup resolvesh3.toResponseagainst the actually-installedh3@1.15.11, finds no such export, and converts it into a failing static named import. The same breaks in reverse forsendunder h3 v2.Fix
Read version-specific symbols through a runtime key so no bundler can fold them into a static named import:
Built output now emits
h3[name]instead ofh3.toResponse, so Rollup keepsimport * as h3with runtime indexing.Test
test/dist-bundling.test.tsRollup-bundles the builtdist/index.mjsagainst a stubh3that — like any single h3 major — exports neithersendnortoResponse, and asserts there are noMISSING_EXPORTwarnings. Verified it catches the regression: the oldh3.toResponsepattern produces exactly"toResponse" is not exported by ...; the fixed pattern produces none. Version-independent, so it runs in every CI matrix cell.🤖 Generated with Claude Code