You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Odd interaction between sideEffects:false and a Worker #12646
Here, I'm using a Worker that shares some code with the main thread, but I'm also using sideEffects: false in package.json.
(In the original code the latter is auto-generated by 3rd-party tooling, but it's not important)
What is the current behavior?
The main thread is bundled correctly, but the import in the Worker resolves to undefined and throws when optimizations are enabled.
This doesn't happen when I change sideEffects to true. Maybe this makes it somehow expected behaviour, but it seems odd that Worker code is still correctly included (after all, the only purpose of Workers is to perform side-effects), it's just the import that doesn't resolve.
What is the expected behavior?
The import in Worker should resolve to actual function foo.
Other relevant information:
webpack version: 5.21.2
hmm yeah I see. The worker entrypoint is side-effect-free, so it thinks nothing is needed at all, but still included it. So it probably should either create a empty worker bundle (as there is no side effect, so everything can be removed), or implicitly marking worker entries as non-side-effect-free, or emitting an error/warning that side-effect-free modules can't be used as worker entries since this doesn't have any effect.
or implicitly marking worker entries as non-side-effect-free
I think this would be the expected behaviour, Workers are more similar to entry points than modules. Or would you exclude application entry point too when sideEffects: false is present?
Would make sense. But at least there should be a warning, as one is incorrectly making it as side-effect-free.
Idk, to me personally entry points being excluded from default side-effect-free list felt like a feature not a bug 😅 So I thought Workers could be naturally excluded too.
Ok there is a fix, but I still want to note that your worker files is incorrectly flagged as side-effect-free and we might add a warning for that in future. Also for entrypoints.
In this case I don't have much control over sideEffects: false (it's generated by wasm-pack, and it's been unmtaintained for some time now), so a fix at least for now is surely helpful.
Activity
alexander-akait commentedon Feb 10, 2021
I think it critical, thanks for the issue
sokra commentedon Feb 10, 2021
hmm yeah I see. The worker entrypoint is side-effect-free, so it thinks nothing is needed at all, but still included it. So it probably should either create a empty worker bundle (as there is no side effect, so everything can be removed), or implicitly marking worker entries as non-side-effect-free, or emitting an error/warning that side-effect-free modules can't be used as worker entries since this doesn't have any effect.
RReverser commentedon Feb 10, 2021
I think this would be the expected behaviour, Workers are more similar to entry points than modules. Or would you exclude application entry point too when
sideEffects: falseis present?sokra commentedon Feb 10, 2021
Would make sense. But at least there should be a warning, as one is incorrectly making it as side-effect-free.
Once you wrap it into a new entry with
import "./old-entry.js"it would be excluded... That seems a bit inconsistent...I tried
that fixes the problem.
btw.
will put
utils.jsinto it's own chunkRReverser commentedon Feb 10, 2021
Idk, to me personally entry points being excluded from default side-effect-free list felt like a feature not a bug 😅 So I thought Workers could be naturally excluded too.
sokra commentedon Feb 10, 2021
yeah, just found code that enforces entrypoints to to be considered as having side-effects^^
RReverser commentedon Feb 10, 2021
Ah, so it is intended. Good to know.
In that case Workers should probably be handled in the same way.
enforce side-effects on async entries similar to normal entrypoints
sokra commentedon Feb 10, 2021
Ok there is a fix, but I still want to note that your worker files is incorrectly flagged as side-effect-free and we might add a warning for that in future. Also for entrypoints.
RReverser commentedon Feb 10, 2021
That was quick. Thanks!
In this case I don't have much control over
sideEffects: false(it's generated by wasm-pack, and it's been unmtaintained for some time now), so a fix at least for now is surely helpful.RReverser commentedon Feb 10, 2021
Interesting, why is
usedExportsused by default? It seems like sharing at least a subset of code is always benefitial?RReverser commentedon Feb 10, 2021
I actually think I found another bug :(
RReverser commentedon Feb 10, 2021
Reported in #12652.