Skip to content

During Legacy builds worker files are not generated with renderModernChunks set to false #18558

Open
@christowiz

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.

image

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 (or npm run build)
  • View /dist/assets, no worker file exists
    • image
  • View /dist/assets/index-legacy-HASH.js file to see reference to worker file

image

Testing

  • Run vite preview or npx serve dist
  • In preview mode console will log errors and serve will display 404 errors for missing worker file

With Modern

  • Change renderModernChunks to true or remove completely from vite.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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions