Skip to content

[Bug]: Incorrect chunking with sideeffectful modules #4617

@sapphi-red

Description

@sapphi-red

Reproduction link or steps

  1. Open https://stackblitz.com/edit/github-nci4o6nk-ps3o8u9e?file=src%2Findex.js
  2. pnpm i runs automatically
  3. pnpm run build runs automatically
  4. Run node src/index.js
  5. Run node dist/index.js
  6. Run npm run build:up to use rollup
  7. Run node dist/index.js

What is expected?

node dist/index.js behaves the same with node src/index.js.
In other words, node dist/index.js outputs:

foo
read
read

What is actually happening?

node dist/index.js behaves differently from node src/index.js.
In other words, node dist/index.js outputs:

undefined
read
read

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: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @rolldown/browser:  1.0.0-beta.9-commit.43425a0

Any additional comments?

rollup generates a correct output, but esbuild has the same incorrect behavior (bundler.sxzz.dev)

If setup.js is marked as sideeffect free (enable the plugin in the repro), the output is expected (as moduleSideEffects is lying).

Originally reported at vitejs/rolldown-vite#182

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions