question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webpack removes files specified in package.json sideEffects

See original GitHub issue

Bug 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:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vankopcommented, May 26, 2022

@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 webpack

1reaction
vankopcommented, Apr 1, 2022

webpack does not track transitive sideEffects ( in your case it technically should be since index.js depends on injectDevTools.js), so you should mark all files by yourself.

In other words sideEffects flag does not have transitive state, so in your case index.js is side effects free.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tree Shaking - webpack
Let's add a new utility file to our project, src/math.js , that exports two ... The way this is accomplished is the "sideEffects"...
Read more >
Are you open to a sideEffects comment directive? · Issue #12595
json file and all files in that package are considered to be side-effect free (i.e. imports of those files can be removed if...
Read more >
Webpack sideEffects wont remove unused function
In the babel-loader iam declaring side-effects to false which means that any unused function should me removed from the bundle. But in my...
Read more >
Everything you never wanted to know about side effects
In this blog post I'll explain what side effects are, why webpack needs to know about them, and what it does with this...
Read more >
Angular package format
The primary package.json contains important package metadata, including the ... .d.ts files are used by TypeScript when depending on a given package.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found