webpack removes files specified in package.json sideEffects
See original GitHub issueBug report
What is the current behavior?
Files specified in package.json sideEffects
is removed
If the current behavior is a bug, please provide the steps to reproduce.
Minimum reproduction: https://stackblitz.com/edit/node-thpmrj?file=dist%2Fwebpack.js
Note that src/lib/package.json has sideEffects: ["./injectDevTools.js"]
, but injectDevTools.js
does not show up in final result dist/webpack.js
Interesting findings while debugging:
I added console logging in SideEffectsFlagPlugin.js
, it returns true when checking ‘injectDevTools.js’ against the sideEffects flag
What is the expected behavior?
Files specified in sideEffects should be kept.
In the above example, injectDevTools.js
should be included in final result dist/webpack.js
Other relevant information: webpack version: 5.70.0 Node.js version: 16.14.2 Operating System: Additional tools:
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
@amitbeck please create a small reproducible repo, I will take a look
simple check for you will be set
optimization.sideEffects=false
to disable side effects “check” by webpackwebpack does not track transitive
sideEffects
( in your case it technically should be sinceindex.js
depends oninjectDevTools.js
), so you should mark all files by yourself.In other words
sideEffects
flag does not have transitive state, so in your caseindex.js
is side effects free.