esbuild
esbuild copied to clipboard
[BUG] The interaction between esm and cjs when sideEffects is `false`
When the sideEffects of the library in node_module is false, there may be some problems with the interaction between esm and CommonJS, which is a bit tedious to describe, please see the demo.
How to reproduce:
- git clone https://github.com/bvanjoi/esbuild-bug-demo-under-sideEffects.git
- cd esbuild-bug-demo-under-sideEffects && node index.js.
Results show:
Thanks for the report. I am able to reproduce the issue. However, I'm not immediately sure what the right fix is because I haven't touched this code in a long time. A workaround for now could be to ignore the sideEffects annotation.
Edit: For my own reference, this is a simple end-to-end test that reproduces the issue:
test(['--bundle', 'entry.js', '--outfile=node.js'], {
'entry.js': `import { foo } from 'pkg'; if (foo.bar !== 123 || require('./foo').foo.bar !== 123) throw 'fail'`,
'foo.js': `export let foo = { bar: 123 }`,
'node_modules/pkg/index.js': `export * from '../../foo'`,
'node_modules/pkg/package.json': `{ "sideEffects": false }`,
}),