Skip to content

fix(vite): resolve dev externals without the development condition - #4996

Merged
pi0 merged 1 commit into
mainfrom
fix/vite-dev-ext
Nov 1, 2026
Merged

pi0 merged 1 commit into
mainfrom
fix/vite-dev-ext

Conversation

@pi0x

@pi0x pi0x commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #4994

In vite dev, Vite resolves the app's imports of externalized dependencies with the nitro environment's externalConditions, which included development. Node then resolves the imports inside those files with its own conditions, without development. A package with a development export that another external also imports loaded twice (development build for the app, default build for the other dependency), breaking cross-copy checks such as seroval's.

This drops the mode conditions (development / production) from the external conditions, matching Vite's own default (["node", "module-sync"]) and the production build. They stay in resolve.conditions for inlined code.

  • Regression test: test/vite/external-conditions.test.ts (failed before: app got development, consumer default).
  • Verified with the reporter's repro (packed build): one copy of dual, seroval stream ok.

🤖 Generated with AI assistant

@pi0x
pi0x requested a review from pi0 as a code owner November 1, 2026 15:42
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
nitro.build Ready Ready Preview Nov 1, 2026 3:48pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Findings

Actionable comments posted: 2

Caution

Review failed

The pull request is closed.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: de07d178-f3d6-45e8-9965-88139b85e00b
Commits

Reviewing files that changed from the base of the PR and between 294bdde and faa727c.

Files ignored due to path filters: 7
  • test/vite/external-conditions-fixture/node_modules/@fixture/consumer/index.d.ts is excluded by !**/node_modules/**
  • test/vite/external-conditions-fixture/node_modules/@fixture/consumer/index.js is excluded by !**/node_modules/**
  • test/vite/external-conditions-fixture/node_modules/@fixture/consumer/package.json is excluded by !**/node_modules/**
  • test/vite/external-conditions-fixture/node_modules/@fixture/dual/default.js is excluded by !**/node_modules/**
  • test/vite/external-conditions-fixture/node_modules/@fixture/dual/dev.js is excluded by !**/node_modules/**
  • test/vite/external-conditions-fixture/node_modules/@fixture/dual/index.d.ts is excluded by !**/node_modules/**
  • test/vite/external-conditions-fixture/node_modules/@fixture/dual/package.json is excluded by !**/node_modules/**
Files selected for processing: 4
  • src/build/vite/env.ts
  • test/vite/external-conditions-fixture/server.ts
  • test/vite/external-conditions-fixture/vite.config.ts
  • test/vite/external-conditions.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

Nitro now excludes development and production from Vite external conditions unless Node receives those conditions through --conditions, -C, or NODE_OPTIONS. A Vite integration test checks the resolved values from the app and consumer packages.

Changes: External condition resolution

Layer / File(s) Summary
Parse and filter Node conditions
src/build/vite/env.ts
_nodeConditionsFlag reads condition values from process.execArgv and NODE_OPTIONS. _externalConditions excludes development and production unless Node receives them, while retaining the existing exclusions.
Verify external package resolution
test/vite/external-conditions-fixture/vite.config.ts, test/vite/external-conditions-fixture/server.ts, test/vite/external-conditions.test.ts
The fixture returns values from the app and consumer packages. The integration test checks that both values are default.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: faa727c

Node resolves the imports inside externalized dependencies without it, so
resolving the app's own imports with it loaded a second copy (#4994).
@pi0
pi0 merged commit 4bdbd28 into main Nov 1, 2026
14 checks passed
@pi0
pi0 deleted the fix/vite-dev-ext branch November 1, 2026 15:49

This branch was successfully deployed

1 active deployment
Preview — 231f15f5 Deployed Nov 1, 2026 by vercel[bot]
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.

vite dev: externalized dependencies resolve with the development condition, so a package can load twice

2 participants