Skip to content

fix(build): read chunk import map from environment (fix #23119) - #23120

Closed
rushijagani-dev wants to merge 1 commit into
vitejs:mainfrom
rushijagani-dev:fix/chunk-import-map-env-config
Closed

rushijagani-dev wants to merge 1 commit into
vitejs:mainfrom
rushijagani-dev:fix/chunk-import-map-env-config

Conversation

@rushijagani-dev

Copy link
Copy Markdown

Fixes #23119

This makes the chunk import map build hooks read build.chunkImportMap from the active environment config instead of the root config captured when shared plugin instances are used. With builder.sharedPlugins, an environment-level build.chunkImportMap: true now lets vite:build-import-analysis read the generated import map and produce preload dependency lists for dynamic chunks and their CSS. The CSS post-processing and HTML import-map injection paths also use the environment config and skip missing import-map assets, so an environment that opts out does not crash when another config scope enables the option. Regression coverage exercises both the shared-plugin environment enablement path and the environment opt-out path.

Validation:

  • PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pnpm install passed
  • pnpm exec vitest run packages/vite/src/node/__tests__/build.spec.ts -t 'chunk import map|chunkImportMap' passed under Node v24.4.1
  • pnpm run build passed under Node v24.4.1
  • pnpm run lint passed under Node v24.4.1
  • pnpm run typecheck passed under Node v24.4.1
  • git diff --check passed

Blockers:

  • pnpm install without PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 could not complete locally because the playwright-chromium browser download failed with UNABLE_TO_GET_ISSUER_CERT_LOCALLY. I did not run the full browser-backed pnpm test suite locally for that reason.

@antur84

antur84 commented Jul 31, 2026

Copy link
Copy Markdown

Reporter here — verified against the repro linked in #23119.

I built vite from this branch and from its merge-base (e6b6b167a) and ran the repro's matrix against each:

  • merge-base: 2 broken cells — SCOPE=environment sharedPlugins=1 emits no __vite__mapDeps dep lists, so the lazy chunk's CSS is unreachable, and SCOPE=root sharedPlugins=1 fails with TypeError: Cannot read properties of undefined (reading 'mapping') in vite:css-post.
  • this branch (8f63d8f7a): all 6 cells pass.

@rushijagani-dev

Copy link
Copy Markdown
Author

Thanks for verifying this against the repro matrix and for checking both the merge-base and this branch. Glad to hear both the environment-scoped import map case and the root-scope opt-out crash are fixed here.

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.

build.chunkImportMap on an environment is ignored by vite:build-import-analysis under builder.sharedPlugins

2 participants