wasm-bindgen: In wasm-bindgen 0.2.84 version, webpack cannot generate wasm files

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.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 7
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

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.

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?

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

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!

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')

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)