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

In wasm-bindgen 0.2.84 version, webpack cannot generate wasm files #3276

Closed
linzhipeng98 opened this issue Feb 2, 2023 · 15 comments · Fixed by rustwasm/wasm-pack#1224
Closed
Labels

Comments

@linzhipeng98
Copy link

linzhipeng98 commented Feb 2, 2023

Steps to Reproduce

I created a repo with the problem here

Step1:
npm run i

Step2:
wasm-pack build

Step3:
npm run build

A dist dir contain index.js and wasm file will be generated in the project root; It is expected behavior.

When i change the wasm-bindgen version to 0.2.84 and run
rm -r pkg && wasm-pack build && npm run build

In dist dir, webpack doesn't generate wasm files.

@hschimke
Copy link

hschimke commented Feb 2, 2023

I've noticed this as well, additionally: setting the version of wasm-bindgen back to 83 isn't respected for some reason, and cargo continues building with 84 regardless.

In my case, the files are being generated but they are invalid, and any use of them results in a javascript undefined.

AlexTMjugador added a commit to OptiVorbis/OptiVorbis that referenced this issue Feb 4, 2023
…ression

This regression rendered the OptiVorbis web demo unusable. Upstream
issue: rustwasm/wasm-bindgen#3276
@AlexTMjugador
Copy link

AlexTMjugador commented Feb 4, 2023

I can reproduce this issue on my project too. Trying to use the WASM module from JS in a development server throws a wasm is undefined exception.

@Liamolucko
Copy link
Collaborator

This seems to be a bug in Webpack, triggered by #3152. As a workaround, switching to dynamically importing the wasm-bindgen shim fixes it for some reason.

@Liamolucko
Copy link
Collaborator

It turns out this is happening because wasm-pack sets "sideEffects": false for wasm-bindgen generated code, which is a Webpack-specific flag that tells Webpack it can remove any code whose only impact is a side effect. In #3152, I unwittingly made initialisation rely on side effects, causing this problem.

(So, it's not a Webpack bug, I was a bit quick to assume that.)

I've opened rustwasm/wasm-pack#1224 to fix this. @alexcrichton or @drager, could you take a look at that PR?

@alexcrichton
Copy link
Contributor

Ah sorry, I don't manage the wasm-pack repository myself.

@drager
Copy link
Member

drager commented Feb 17, 2023

It turns out this is happening because wasm-pack sets "sideEffects": false for wasm-bindgen generated code, which is a Webpack-specific flag that tells Webpack it can remove any code whose only impact is a side effect. In #3152, I unwittingly made initialisation rely on side effects, causing this problem.

(So, it's not a Webpack bug, I was a bit quick to assume that.)

I've opened rustwasm/wasm-pack#1224 to fix this. @alexcrichton or @drager, could you take a look at that PR?

Yeah, I will take a look soon. Thanks for looking into and fixing it!

@cryptoquick
Copy link

I tried setting everything back to 0.2.83, by running these steps in this order (after some trial and error):

cargo update -p wasm-bindgen-test --precise 0.3.33
cargo update -p wasm-bindgen-futures --precise 0.4.33
cargo update -p web-sys --precise 0.3.60
cargo update -p js-sys --precise 0.3.60
cargo update -p wasm-bindgen --precise 0.2.83

And then built it with rustc 1.67.1, making sure that the old versions were indeed the ones that were compiled...

But it still didn't solve the issue I ran into in #3306.

@Liamolucko
Copy link
Collaborator

I tried setting everything back to 0.2.83, by running these steps in this order (after some trial and error):

cargo update -p wasm-bindgen-test --precise 0.3.33
cargo update -p wasm-bindgen-futures --precise 0.4.33
cargo update -p web-sys --precise 0.3.60
cargo update -p js-sys --precise 0.3.60
cargo update -p wasm-bindgen --precise 0.2.83

And then built it with rustc 1.67.1, making sure that the old versions were indeed the ones that were compiled...

But it still didn't solve the issue I ran into in #3306.

I can't reproduce this. Could you give more detailed instructions?

@cryptoquick
Copy link

cryptoquick commented Feb 21, 2023

I tried setting everything back to 0.2.83, by running these steps in this order (after some trial and error):

cargo update -p wasm-bindgen-test --precise 0.3.33
cargo update -p wasm-bindgen-futures --precise 0.4.33
cargo update -p web-sys --precise 0.3.60
cargo update -p js-sys --precise 0.3.60
cargo update -p wasm-bindgen --precise 0.2.83

And then built it with rustc 1.67.1, making sure that the old versions were indeed the ones that were compiled...
But it still didn't solve the issue I ran into in #3306.

I can't reproduce this. Could you give more detailed instructions?

I've updated and uploaded my MRE:
https://github.com/cryptoquick/wasm-bindgen-mre

I've made a few more changes, up to here: cryptoquick/wasm-bindgen-mre@ee313c0

Still not working, same error as in README, not sure what else I can do...

I'm sure the cache is clearing too, since each time, I test with a different port on my local server.

@Liamolucko
Copy link
Collaborator

I've updated and uploaded my MRE:

https://github.com/cryptoquick/wasm-bindgen-mre

I've made a few more changes, up to here: cryptoquick/wasm-bindgen-mre@ee313c0

Still not working, same error as in README, not sure what else I can do...

I'm sure the cache is clearing too, since each time, I test with a different port on my local server.

That repo isn't demonstrating the original issue that you had in #3306, it's a completely separate issue which is occurring because you're not running await init() before using the wasm exports on --target web, as people already pointed out in #3306.

The original problem was with --target bundler, not --target web, and that's the issue that I believe is the same as this one and wasn't present in 0.2.83.

@kleinesfilmroellchen
Copy link

I have this exact issue, as soon as I upgrade to web_sys 0.3.61 from 0.3.60 any call to a Rust function from JavaScript results in an undefined error like:

bootstrap.js:2 Error importing `index.js`: TypeError: Cannot read properties of undefined (reading 'on_assembly_change')
    at Module.on_assembly_change (spcasm_web_bg.js:269:10)
    at eval (index.js:36:46)
    at __webpack_require__.a (bootstrap.js:357:13)
    at eval (index.js:1:21)
    at ./index.js (index_js.bootstrap.js:28:1)
    at __webpack_require__ (bootstrap.js:284:33)
    at Function.fn (bootstrap.js:592:21)

(on_assembly_change is the Rust function being called, which sort of has bindings generated, as you can see)

@FlareFlo
Copy link

I have this exact issue, as soon as I upgrade to web_sys 0.3.61 from 0.3.60 any call to a Rust function from JavaScript results in an undefined error like:

bootstrap.js:2 Error importing `index.js`: TypeError: Cannot read properties of undefined (reading 'on_assembly_change')
    at Module.on_assembly_change (spcasm_web_bg.js:269:10)
    at eval (index.js:36:46)
    at __webpack_require__.a (bootstrap.js:357:13)
    at eval (index.js:1:21)
    at ./index.js (index_js.bootstrap.js:28:1)
    at __webpack_require__ (bootstrap.js:284:33)
    at Function.fn (bootstrap.js:592:21)

(on_assembly_change is the Rust function being called, which sort of has bindings generated, as you can see)

I get issues with my own functions, or some stack pointer calls, such as Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '__wbindgen_add_to_stack_pointer')

@cryptoquick
Copy link

That repo isn't demonstrating the original issue that you had in #3306, it's a completely separate issue which is occurring because you're not running await init() before using the wasm exports on --target web, as people already pointed out in #3306.

The original problem was with --target bundler, not --target web, and that's the issue that I believe is the same as this one and wasn't present in 0.2.83.

I actually updated the comment you responded to only a few minutes after I posted it. Please take another look.

@cryptoquick
Copy link

@Liamolucko I just took another look at my code and realized what you were explaining. I've fixed it and the MRE passes, so you are correct in that it is no longer relevant to this discussion.

@Liamolucko
Copy link
Collaborator

This is now fixed in wasm-pack v0.11.0.

tkmcmaster added a commit to FamilySearch/pewpew that referenced this issue Apr 26, 2023
* Fixed the HDR Histogram build for webpack

- rustwasm/wasm-bindgen#3276 (comment)
- rustwasm/wasm-pack#1224

* Updated Viewer dependencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants