Skip to content

fix(vite): respect bun/deno export conditions in dev server#4397

Merged
pi0 merged 4 commits into
mainfrom
fix/vite-runtime-conditions
Jun 30, 2026
Merged

fix(vite): respect bun/deno export conditions in dev server#4397
pi0 merged 4 commits into
mainfrom
fix/vite-runtime-conditions

Conversation

@pi0x

@pi0x pi0x commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

When the Nitro dev server runs under Bun (bun --bun) or Deno, the Vite module runner resolves the node export condition, so packages are loaded through their node entry instead of their runtime-native one.

This PR adds _devRuntimeConditions(ctx), used by both the Nitro and service environments, to prepend the host runtime's export condition:

  • under Bun → prepend "bun"
  • under Deno → prepend "deno"

Scope

This only applies in dev and only with the default node-worker runner, where the module runner executes in a worker thread of the same host runtime (Bun ⇒ Bun, Deno ⇒ Deno).

Process-based runners (bun-process, deno-process, node-process, …) and miniflare execute in a different runtime than the host, so the host-detected condition is intentionally not applied to them — otherwise it would leak the wrong condition into their resolution.

This is a generic fix to honor bun/deno export conditions; it is not tied to any single dependency.

When the Nitro dev server runs under Bun or Deno, the Vite module runner
resolved the `node` export condition, so `srvx`'s `FastResponse` became the
node adapter's `NodeResponse` wrapper. `Bun.serve`/`Deno.serve` strictly
require a native `Response` and reject it, crashing the dev server.

Prepend the matching `bun`/`deno` export condition in dev so packages like
`srvx` resolve to their runtime-native adapter (native `Response`). `node`
stays as a fallback; production builds are unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pi0x pi0x requested a review from pi0 as a code owner June 30, 2026 10:44
@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nitro.build Ready Ready Preview, Comment Jun 30, 2026 12:41pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6810721b-9dfe-4525-bc8f-1284243e0f66

📥 Commits

Reviewing files that changed from the base of the PR and between dbc1e86 and 4f26c1c.

📒 Files selected for processing (1)
  • src/build/vite/env.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/build/vite/env.ts

📝 Walkthrough

Walkthrough

Adds dev-only export condition selection for Bun and Deno in src/build/vite/env.ts, and centralizes dev runner resolution for _loadRunner and _isWorkerdRunner.

Changes

Dev runtime export conditions

Layer / File(s) Summary
_resolveConditions helper and environment call sites
src/build/vite/env.ts
Adds _resolveConditions(ctx) to prepend Bun or Deno to exportConditions during non-workerd dev, and updates both environment constructors to use it.
_devRunner shared lookup
src/build/vite/env.ts
Factors dev runner selection into _devRunner(ctx), then reuses it in _loadRunner and _isWorkerdRunner(ctx).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • nitrojs/nitro#3836: Both change src/build/vite/env.ts and refactor dev runner/environment setup logic.
  • nitrojs/nitro#3886: Both adjust how exportConditions are assembled in Nitro’s Vite environment setup.
  • nitrojs/nitro#4338: Both modify runner selection and workerd/miniflare detection in src/build/vite/env.ts.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed It follows conventional commits and accurately describes the Bun/Deno export-condition fix in dev.
Description check ✅ Passed The description is directly related to the changeset and explains the dev-server export-condition behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/vite-runtime-conditions

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jun 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4397

commit: 4f26c1c

…nner

Only prepend the host bun/deno condition when the module runner shares the
host runtime (default node-worker). Process-based and miniflare runners
execute in a different runtime and must not inherit it. Also dedupe runner
name resolution into a shared _devRunner() helper.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pi0x pi0x changed the title fix(vite): use runtime-native export conditions for bun/deno dev server fix(vite): respect bun/deno export conditions in dev server Jun 30, 2026
Externalized deps in dev now resolve their bun/deno-native entry too,
matching the bundled `conditions` behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The helper runs on all paths (it early-returns outside dev/node-worker),
so the `dev` prefix was misleading.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pi0 pi0 merged commit 1310a58 into main Jun 30, 2026
13 checks passed
@pi0 pi0 deleted the fix/vite-runtime-conditions branch June 30, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants