Skip to content

Vite excludes side effects modules from the bundle in production mode. #6740

@jacksonrr3

Description

@jacksonrr3

Describe the bug

I use Vite to build my project. After updating the vite package from 2.6.14 to 2.7.13 I face the following issue: A module, imported for the side effects only, excluded from the bundle if the root module has the sideEffects property set to false in the package.json.

I've also tried to create a bundle using rollup or webpack: the result bundles contained modules with side effects.
You can find a sample project attached.

To reproduce, install dependencies and call the build script. Then search for the ui.stub.secondary string in the dist folder. It exists in the rollup and webpack bundles, but in the vite bundle, it exists only in the .map file.

What changes between the Vite versions lead to such behavior? If this behavior is by design now? If yes, how can we configure Vite to get the old behavior back?

Reproduction

https://github.com/jacksonrr3/vite_issue_project

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
    Memory: 4.22 GB / 15.77 GB
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1023.0), Chromium (97.0.1072.76)
    Internet Explorer: 11.0.19041.906
  npmPackages:
    vite: ^2.6.14 => 2.7.13

Used Package Manager

npm

Logs

No response

Validations

Metadata

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