fix(config): prepend bun export condition under bun runtime#4229
fix(config): prepend bun export condition under bun runtime#4229sotasan wants to merge 1 commit intonitrojs:mainfrom
Conversation
|
@sotasan is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe export-condition resolver now adds the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When running the dev server under `bun --bun`, `_resolveExportConditions` only pushed "node" to Vite's resolve conditions. This caused Vite's ModuleRunner to load srvx's and h3's Node adapters inside the dev worker, returning a srvx `NodeResponse` to `Bun.serve` — which Bun rejects, falling back to its default response and breaking every `/_nitro/*` request with a Parse Error. Detect Bun via `"Bun" in globalThis` (matching the existing pattern in `src/presets/vercel/utils.ts`) and prepend "bun" so it wins for packages declaring both conditions, while keeping "node" for packages that only declare "node". Pure Node setups are unchanged. Closes nitrojs#4228
7824ce1 to
1e0c12b
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/config/resolvers/export-conditions.ts (1)
23-29: Consider preserving"node"alongside"bun"when Bun is detected.Bun's module resolver applies both
"bun"and"node"conditions by default for Node.js compatibility. Dropping"node"here breaks resolution for dependencies that only ship a"node"export without a"bun"entry. The dedupSetat line 33 prevents duplicates, and the vercel preset's guard at line 44 prevents double-pushes, so this is safe.♻️ Proposed adjustment
if (opts.node) { if ("Bun" in globalThis) { - conditions.push("bun"); + conditions.push("bun", "node"); } else { conditions.push("node"); } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/config/resolvers/export-conditions.ts` around lines 23 - 29, When opts.node is true and the runtime is Bun (detected via "Bun" in globalThis), preserve both "bun" and "node" in the conditions array instead of replacing "node" with "bun"; update the branch in export-conditions.ts that currently does if (opts.node) { if ("Bun" in globalThis) { conditions.push("bun"); } else { conditions.push("node"); } } to push both conditions when Bun is present (conditions.push("bun"); conditions.push("node");) so dependencies that only export "node" still resolve; keep the existing dedup Set and the vercel preset guard behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/config/resolvers/export-conditions.ts`:
- Around line 23-29: When opts.node is true and the runtime is Bun (detected via
"Bun" in globalThis), preserve both "bun" and "node" in the conditions array
instead of replacing "node" with "bun"; update the branch in
export-conditions.ts that currently does if (opts.node) { if ("Bun" in
globalThis) { conditions.push("bun"); } else { conditions.push("node"); } } to
push both conditions when Bun is present (conditions.push("bun");
conditions.push("node");) so dependencies that only export "node" still resolve;
keep the existing dedup Set and the vercel preset guard behavior unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1c1598cd-c7f5-49be-98ab-ccae8a521e42
📒 Files selected for processing (1)
src/config/resolvers/export-conditions.ts
commit: |
Linked Issue
Closes #4228
Description
_resolveExportConditionsonly pushed"node"to Vite's resolve conditions, regardless of the actual dev runtime. Underbun --bun vite dev, this caused Vite'sModuleRunner(inside the dev worker) to loadsrvx/dist/adapters/node.mjsandh3/dist/_entries/node.mjs. The Node adapter'sNodeResponsewrapper class is then returned from h3's response pipeline toBun.serve— which rejects it (error: Expected a Response object, but received 'NodeResponse {...}') and falls back to its default response, breaking every/_nitro/*request with aParse Errorfromnode:_http_client:230.Change
Detect Bun via
"Bun" in globalThisand prepend"bun"to the conditions list when running under Bun."node"is still pushed unconditionally, so packages that only declare a"node"export condition still resolve correctly. For packages declaring both (srvx, h3) the order of the resolve conditions causes"bun"to win — picking the Bun adapter as intended.Pattern matches the existing
"Bun" in globalThischeck insrc/presets/vercel/utils.ts:438.Verified
dist/_chunks/nitro.mjsin a real Nitro + Vite app —GET /_nitro/tasks,GET/POST /_nitro/tasks/:name, and the mainGET /route all return 200 underbun --bun vite dev. Scheduled tasks continue to fire.pnpm lintpasses.pnpm typecheckpasses for the modified file (other unrelated type errors are pre-existing onmain).pnpm buildproduces a clean bundle with the expected logic."Bun" in globalThischeck is false, so the only conditions pushed are the same asmain).