Skip to content

fix(optimize-deps): avoid "unsupported" warnings for browser:false mappings - #23590

Merged
sapphi-red merged 2 commits into
vitejs:mainfrom
charan-rathore:fix/browser-false-optimizer
Sep 30, 2026
Merged

sapphi-red merged 2 commits into
vitejs:mainfrom
charan-rathore:fix/browser-false-optimizer

Conversation

@charan-rathore

Copy link
Copy Markdown
Contributor

Some packages use browser: false in their package settings to say an import should be empty in the browser. Vite's dependency optimizer currently treats that import like an unsupported Node module. As a result, it shows warnings when the package reads properties from the empty module.

The two cases already have different internal IDs. A browser: false import uses __vite-browser-external without a suffix. An unsupported Node module uses __vite-browser-external:<id>. This change loads an empty module for the first case and keeps the existing warning for the second. It adds a test for a package with a browser: false mapping. The existing tests still check warnings for unsupported Node modules.

In the reproduction for #23512, this removes 23 warnings from PostCSS without changing the page's CSS output. A node:fs import that is not mapped to false still warns. Build and preview behavior is unchanged. The reproduction gist's lockfile needs its absolute package paths changed to node_modules/ before npm ci works; that lockfile is not changed here.

Fixes #23512.

Patch drafted with AI assistance (Grok 4.7). I reviewed it and ran the monorepo build, Vite typecheck, the optimizer unit tests, the optimize-deps serve and build playground tests, lint, and formatting.

@sapphi-red sapphi-red changed the title fix: avoid browser-external warnings for browser:false mappings fix(optimize-deps): avoid "unsupported" warnings for browser:false mappings Sep 30, 2026
@sapphi-red sapphi-red added p2-edge-case Bug, but has workaround or limited in scope (priority) feat: deps optimizer Dependencies Optimization labels Sep 30, 2026
@sapphi-red
sapphi-red merged commit 5e4b9ca into vitejs:main Sep 30, 2026
27 checks passed
kazupon added a commit to kazupon/vrowzer that referenced this pull request Sep 30, 2026
)

* chore(vite-dev-server): update optimizeDeps.include comment

Port vitejs/vite#23489 (6a84c7210).

* fix(vite-dev-server): don't skip imports whose binding starts with type

Port vitejs/vite#23540 (39330f489).

* chore(vite-dev-server): add debug log when waiting for dep before init

Port vitejs/vite#23566 (63567c73a).

* fix(vite-dev-server): resolve pending discovered dep processing on close before init

Port vitejs/vite#23567 (5f894339d).

* fix(vite-dev-server): preserve excluded optional peer require fallbacks

Port vitejs/vite#23600 (a2bd6fa89).

* fix(vite-dev-server): pass queries to renderBuiltUrl

Port vitejs/vite#23586 (744269e5b). The html.ts part is not ported because buildHtmlPlugin does not exist in this fork. Update the asset URL tests for the new placeholder format, where the postfix is carried in URL metadata instead of trailing the token.

* fix(vite-dev-server): avoid unsupported warnings for browser:false mappings

Port vitejs/vite#23590 (5e4b9ca3d).
@charan-rathore
charan-rathore deleted the fix/browser-false-optimizer branch October 1, 2026 09:12
@github-actions github-actions Bot mentioned this pull request Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: deps optimizer Dependencies Optimization p2-edge-case Bug, but has workaround or limited in scope (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid browser-external warnings for imports explicitly disabled by browser mappings

3 participants