During Legacy builds worker files are not generated with renderModernChunks
set to false #18558
Description
Describe the bug
I am trying to create a legacy-only build (no modern chunks) using the Legacy plugin that outputs working code which includes the web worker files.
What is happening is that when renderModernChunks
is set to false the worker file is not created during the build but is still referenced inside the bundled code. When renderModernChunks
is either set to true
or absent from the config the worker files are generated correctly.
This works correctly in dev
mode
From a cursory examination I found that if I removed the conditional inside the legacyPostPlugin.configResolved
method the worker files are generated correctly and the index.html
file is output correctly. I haven't had time to dig any deeper.
Note: The reason I need a legacy only build is the HTML that is generated which supports both legacy and modern does not work on older browsers. This is a separate issue.
Reproduction
https://stackblitz.com/edit/vitejs-vite-zsxp4m?file=vite.config.js
Steps to reproduce
- Run
vite build
(ornpm run build
) - View
/dist/assets
, no worker file exists - View
/dist/assets/index-legacy-HASH.js
file to see reference to worker file
Testing
- Run
vite preview
ornpx serve dist
- In
preview
mode console will log errors andserve
will display 404 errors for missing worker file
With Modern
- Change
renderModernChunks
totrue
or remove completely fromvite.config.js
- Run
vite build
- View
/dist/assets
, worker file exists
Difference being the generated index.html
file
System Info
## StackBlitz
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@vitejs/plugin-legacy: ^5.4.3 => 5.4.3
vite: ^5.4.10 => 5.4.10
## Local
System:
OS: macOS 14.6.1
CPU: (10) arm64 Apple M1 Pro
Memory: 152.56 MB / 16.00 GB
Shell: 5.9 - /opt/homebrew/bin/zsh
Binaries:
Node: 22.9.0 - ~/Library/pnpm/node
npm: 10.9.0 - ~/Library/pnpm/npm
pnpm: 9.7.1 - /opt/homebrew/bin/pnpm
bun: 1.1.30 - ~/.bun/bin/bun
Watchman: 2024.10.21.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 130.0.6723.92
Chrome Canary: 132.0.6813.0
Safari: 18.0
npmPackages:
@vitejs/plugin-legacy: 5.4.3 => 5.4.3
vite: 5.4.10 => 5.4.10
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.