Skip to content
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 should not be false now #1235

Open
Menci opened this issue Feb 25, 2023 · 0 comments
Open

sideEffects should not be false now #1235

Menci opened this issue Feb 25, 2023 · 0 comments

Comments

@Menci
Copy link

Menci commented Feb 25, 2023

🐛 Bug description

To enable tree-shaking of bundlers, wasm-pack generates package.json with sideEffects: false. It's OK before since the entry module generated by wasm-bindgen didn't have side effects:

import * as wasm from "./{wasm_name}.wasm";
export * from "./{js_name}.js";

But after rustwasm/wasm-bindgen@721c86c, it now has side effects:

import * as wasm from "./{wasm_name}.wasm";
import { __wbg_set_wasm } from "./{js_name}.js";
__wbg_set_wasm(wasm);
export * from "./{js_name}.js";

Now sideEffects: false will let bundle remove the __wbg_set_wasm call from the entry module, which causes the let wasm; variable in binding module to be undefined.

🤔 Expected Behavior

What should have happened?

The sideEffects property should be set to a list of files with side effects. I think it should be the entry module's filename, i.e. sideEffects: ["./{entry_name}.js"].

👟 Steps to reproduce

Clear steps describing how to reproduce the issue, including commands and flags run. If you are seeing an error, please include the full error message and stack trace.

  • rustwasm-bug-repro.zip
  • Unzip the project, run yarn to install dependencies and run yarn build to build a bundle.
  • Open dist/assets/index-*.js. The file is not minified. You can see the __wbg_set_wasm function and assignment to let wasm; variable is tree-shaked.
  • Modify node_modules/pkg/package.json (not pkg/package.json, the one to be used by Vite is in node_modules), set sideEffects to ["./game_of_life.js"].
  • Rerun yarn build
  • Open dist/assets/index-*.js. The file is not minified. You can see the __wbg_set_wasm function is present and called correctly.

The pkg directory in the archive is generated from https://github.com/BLaZeKiLL/game-of-life/tree/69443864176a39415c93c82d361caf2393126b80. With wasm-pack 0.10.3.

🌍 Your environment

Include the relevant details of your environment.
wasm-pack version: 0.10.3
rustc version: 1.64.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant