-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"sideEffects" annotation in package.json may be out of date #4248
Comments
Thanks for reporting this, I'll take a look. We initally set this up to work with webpack 4 but can check on the behaviour in webpack 5. At least at that point we needed to have the explicit sideEffects list present to get the behaviour we want. |
Thanks for taking a look! I'm sorry about this class of problems being an issue. Ideally One more thing to point out is that it's not just the
Presumably the |
Thanks for the detailed report @evanw, We missed a few files in our sideEffects listing. I've made a PR to address this and unblock this issue, and will be testing out webpacks new ability to do without the sideEffects field more extensively. It would be great if we don't have to track this manually, but will have to make the call as to whether we need to support webpack 4. |
I'm working on a bug filed by a user of this library against esbuild, a bundler I work on. It looks to me like this library uses the sideEffects annotation in
package.json
to indicate that most files in the package do not have side effects. However, they do actually have side effects and this annotation causes the resulting bundle to be broken.System information
Describe the current behavior
I tested this by bundling this example code from your readme:
Bundling that with
webpack ./example.js
(Webpack version 5.4.0, the current one) and running the bundle in the browser with a script tag throwsError: Backend name 'wasm' not found in registry
.Describe the expected behavior
I expect
works
to be printed to the console.Suggested fix
The easiest way to fix this is to remove the
sideEffects
field from yourpackage.json
files. This should make sure the library remains correct when bundled.A harder way to fix this would be to go through all of your files and figure out which ones have side effects, and then include them in that list. For example, at least the file
dist/backend_wasm.js
should be in there because it contains a call toregisterBackend('wasm')
. This is harder because you will have subtle correctness issues if you later on change your files (introduce new ones, move code between files, etc.) and forget to update thesideEffects
field correctly.Standalone code to reproduce the issue
Additional files used:
package.json
index.html
The text was updated successfully, but these errors were encountered: