fix: use h3 alias only in nitro-v2-plugin #5370
main fromrefs/pull/5370/head·merged by schiller-manuel(GitHub profile, opens in a new tab) avoid issues with nitro v3
see https://github.com/nitrojs/nitro/issues/3613#issuecomment-3368990799
Summary by CodeRabbit#
Bug Fixes
- Improved build compatibility by ensuring consistent resolution of h3 imports in the Nitro Vite plugin.
Chores
- Added an alias to support h3 v1 for internal tooling.
- Upgraded server runtime dependency to h3 2.0.0-beta.5.
- Updated Vite configuration to disable CommonJS output.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-server-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: nitro-v2-vite-plugin
View your CI Pipeline Execution ↗ for commit edd4f1302cb45b4371737f9f74c37dae55506627
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 1m 16s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 4s View ↗
☁️ Nx Cloud last updated this comment at
2025-10-05 13:26:20UTCMore templates
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-static
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5370@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5370@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5370@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5370@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5370@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5370@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5370@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5370@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5370@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5370@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5370@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5370@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5370@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5370@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5370@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5370@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5370@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5370@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5370@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5370@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5370@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5370@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5370@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5370@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5370@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5370@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5370@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5370@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5370@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5370@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5370@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5370@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5370@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5370commit:
edd4f13Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/nitro-v2-vite-plugin/src/index.ts (1)
118-130: Consider refining the resolution condition for precision.The custom
resolveIdhook correctly redirectsh3imports toh3-v1for Nitro v2 compatibility. However, the conditionimporter?.includes('nitropack')uses a broad string match that could match unintended paths.Consider making the condition more precise and adding an explanatory comment:
{ name: 'resolve', + // Redirect h3 imports to h3-v1 for Nitro v2 compatibility + // See: https://github.com/nitrojs/nitro/issues/3613 resolveId(source, importer) { if ( - (importer?.includes('nitropack') || + (importer?.includes('/nitropack/') || importer === virtualEntry) && source === 'h3' ) { return h3 } return null }, },The refined condition uses
/nitropack/to match path segments more precisely, reducing the risk of false positives. The comment documents the purpose and references the related issue.📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between dc320144a5c1b00e443e54aed29a502f57e362ff and 3ab08790162290f0f07bd23a033a289288ed098e.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (5)
packages/nitro-v2-vite-plugin/package.json(1 hunks)packages/nitro-v2-vite-plugin/src/index.ts(4 hunks)packages/nitro-v2-vite-plugin/vite.config.ts(1 hunks)packages/start-server-core/package.json(1 hunks)packages/start-server-core/src/request-response.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/start-server-core/src/request-response.tspackages/nitro-v2-vite-plugin/vite.config.tspackages/nitro-v2-vite-plugin/src/index.ts
packages/{*-start,start-*}/**
📄 CodeRabbit inference engine (AGENTS.md)
Name and place Start framework packages under packages/-start/ or packages/start-/
Files:
packages/start-server-core/src/request-response.tspackages/start-server-core/package.json
**/package.json
📄 CodeRabbit inference engine (AGENTS.md)
Use workspace:* protocol for internal dependencies in package.json files
Files:
packages/start-server-core/package.jsonpackages/nitro-v2-vite-plugin/package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (6)
packages/start-server-core/package.json (1)
71-71: LGTM! Version update from aliased h3-v2 to direct h3 package.The change from the alias
h3-v2to the directh3package at version2.0.0-beta.5is correct and aligns with the import updates inrequest-response.ts. The version bump includes new features like universal fetch handlers and middleware improvements.Since h3 v2 is still in beta, ensure that the version bump from beta.4 to beta.5 doesn't introduce breaking changes affecting your usage. Based on learnings, the beta.5 release includes middleware subsystem refactors and new handler types. Test critical code paths that use h3 session, cookie, and request/response utilities.
packages/start-server-core/src/request-response.ts (1)
22-22: LGTM! Import path correctly updated.The import path change from
h3-v2toh3aligns with the dependency update inpackage.json. All imported symbols remain unchanged, ensuring consistent behavior.packages/nitro-v2-vite-plugin/package.json (1)
64-65: LGTM! h3-v1 alias added for Nitro v2 compatibility.The
h3-v1alias dependency correctly pins h3 v1 for Nitro v2, allowing it to coexist with h3 v2 used elsewhere in the monorepo. The version range^1.15.4is appropriate for stable v1 releases.packages/nitro-v2-vite-plugin/vite.config.ts (1)
12-12: Verify consistency with package.json "main" field.Setting
cjs: falsedisables the CommonJS build, butpackage.jsonline 43 still declares"main": "dist/cjs/index.cjs". Since theexportsfield (lines 45-53) only provides animportcondition and the package requires Node >=22.12 (line 60), this package is effectively ESM-only.Consider either:
- Removing the
"main"and"module"fields frompackage.jsonif CJS support is not needed, or - Keeping
cjs: true(default) if legacy tooling compatibility is required.
Given the modern Node.js requirement, removing the legacy fields is likely the cleaner approach.
packages/nitro-v2-vite-plugin/src/index.ts (2)
6-6: LGTM! Correct use of createRequire for ESM module resolution.The
createRequireimport and usage are appropriate for resolving theh3-v1module path in an ESM context.Also applies to: 19-19
97-97: LGTM! h3-v1 path resolution at build time.Resolving the
h3-v1path during the build phase ensures consistent module resolution for the customresolveIdhook.
Sign in to join this conversation.
Walkthrough#
Adds an
h3-v1alias to Nitro V2 Vite plugin deps, injects a RollupresolveIdhook that mapsimport 'h3'to the resolvedh3-v1for specific importers, setscjs: falsein the plugin Vite config, and updatesstart-server-coreto importh3@2.0.0-beta.5.Changes#
packages/nitro-v2-vite-plugin/package.json,packages/start-server-core/package.jsonh3-v1alias (npm:h3@^1.15.4) to nitro plugin deps; replacesh3-v2 (npm:h3@2.0.0-beta.4)withh3@2.0.0-beta.5instart-server-core.packages/nitro-v2-vite-plugin/src/index.tscreateRequire, resolvesh3-v1at runtime, and injects a RollupresolveIdhook to map imports of'h3'to the resolvedh3-v1path for nitropack-related or virtual entry importers.packages/nitro-v2-vite-plugin/vite.config.tscjs: falsein thetanstackViteConfigoptions passed to Vite config.packages/start-server-core/src/request-response.tsh3-v2toh3without API signature changes.Sequence Diagram(s)#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs#
Poem#
Pre-merge checks and finishing touches#
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 3ab08790162290f0f07bd23a033a289288ed098e and edd4f1302cb45b4371737f9f74c37dae55506627.
📒 Files selected for processing (2)
packages/nitro-v2-vite-plugin/package.json(1 hunks)packages/nitro-v2-vite-plugin/src/index.ts(4 hunks)🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/nitro-v2-vite-plugin/src/index.ts⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (1)
Comment `@coderabbitai help` to get the list of available commands and usage tips.