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
There have already been some good discussions on the challenges of circular dependencies (#32) but I'm wondering if there is anything else we can do to solve a specific subset of the problem.
My specific problem is that when attempt_direct_import@crates/cli-support/src/js/mod.rs is used we generate js that looks like this:
However in the case of __wbg_clearTimeout_f42b256aef985387 we're exporting a const which can't be referenced before use, so webpack will silently throw this exception:
You can see the bug by running npm run start and noticing that our wasm never loads.
If you would like to see the workaround in action you can uncomment this block
If you would like to debug the webpack exception for yourself you can run npm run build and insert the relevant console.log statements in the generated output.
Additional Context
I'm wondering if the easiest answer is to just change attempt_direct_import to return a function instead of a const?
The text was updated successfully, but these errors were encountered:
Fixesrustwasm#3102Fixesrustwasm#3149
I've changed the `*_bg.js` file to not import from the wasm module, eliminating the circular dependency between them.
It begins with an undefined `let wasm` which gets initialized by the user-facing JS file before calling `__wbindgen_start`, by calling an exported function `__wbg_set_wasm` that sets `wasm`.
* Get rid of the circular dependency when targeting ES modules
Fixes#3102Fixes#3149
I've changed the `*_bg.js` file to not import from the wasm module, eliminating the circular dependency between them.
It begins with an undefined `let wasm` which gets initialized by the user-facing JS file before calling `__wbindgen_start`, by calling an exported function `__wbg_set_wasm` that sets `wasm`.
* fmt
* Tweak formatting & update reference tests
Describe the Bug
There have already been some good discussions on the challenges of circular dependencies (#32) but I'm wondering if there is anything else we can do to solve a specific subset of the problem.
My specific problem is that when
attempt_direct_import@crates/cli-support/src/js/mod.rs
is used we generate js that looks like this:It seems that in most cases bundlers don't have issues with circular dependencies because:
#[wasm_bindgen(start)]
seems to force a workable ordering between_bg.js
and_bg.wasm
However in the case of
__wbg_clearTimeout_f42b256aef985387
we're exporting a const which can't be referenced before use, so webpack will silently throw this exception:(Retrieved by adding
console.log(err)
to the error handler in thebody
call in__webpack_require__.a
)As I mentioned one workaround is to add a start function with
#[wasm_bindgen(start)]
however this is less than ideal.Steps to Reproduce
I created a sample repo with the problem here
You can see the bug by running
npm run start
and noticing that our wasm never loads.If you would like to see the workaround in action you can uncomment this block
If you would like to debug the webpack exception for yourself you can run
npm run build
and insert the relevantconsole.log
statements in the generated output.Additional Context
I'm wondering if the easiest answer is to just change
attempt_direct_import
to return a function instead of a const?The text was updated successfully, but these errors were encountered: