Skip to content

Inline HTML <script type="module"> is tree-shaken away when package.json has a restrictive sideEffects allowlist (Vite 8 / Rolldown) #22620

Description

@jgerigmeyer

Describe the bug

When package.json declares a sideEffects allowlist, vite build drops the entire body of an inline <script type="module"> in an HTML entry. Rolldown applies the package's own sideEffects: false contract to the inline script's virtual html-proxy module and prunes it wholesale — even statements with obvious side effects (document.title = ..., window.x = ..., console.log(...)).

The emitted page ends up loading only the modulepreload-polyfill helper chunk; none of the inline script survives. This worked on Vite 7 (Rollup) and regressed on Vite 8 (Rolldown).

An inline HTML script is an entry, not an importable module of the package, so the package's sideEffects declaration arguably should not govern whether its statements are kept.

Reproduction

https://stackblitz.com/edit/vitejs-vite-aw3kxbtn?file=dist%2Fassets%2Findex-Dezn_h7o.js

Steps to reproduce

  1. npm run build
  2. Inspect dist/.

Expected: the built index.html loads a chunk containing the inline script (sets document.title, window.__inlineRan, logs).

Actual: the only emitted chunk is dist/assets/index-*.js (~0.69 kB — just the modulepreload-polyfill helper). The inline script's code is gone.

Changing sideEffects to true (or removing it) makes the inline script survive, confirming the allowlist is the trigger.

System Info

System:
    OS: macOS 26.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 113.80 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.11.1 - /Users/jonny/.nvm/versions/node/v24.11.1/bin/node
    Yarn: 1.22.21 - /Users/jonny/.nvm/versions/node/v24.11.1/bin/yarn
    npm: 11.6.2 - /Users/jonny/.nvm/versions/node/v24.11.1/bin/npm
    pnpm: 8.15.5 - /Users/jonny/.nvm/versions/node/v24.11.1/bin/pnpm
    Watchman: 2025.04.28.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 118.0.5993.117
    Chrome Canary: 151.0.7875.0
    Firefox: 150.0
    Safari: 26.5
  npmPackages:
    vite: ^8.0.16 => 8.0.16

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: upstreamBug in a dependency of Vitefeat: htmlp2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions