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

Work around for building with webpack5 #2512

Merged
merged 6 commits into from
Apr 19, 2021
Merged

Work around for building with webpack5 #2512

merged 6 commits into from
Apr 19, 2021

Conversation

nokotan
Copy link
Contributor

@nokotan nokotan commented Mar 29, 2021

This pr will be solution to #2343.
In this PR, binding functions are declared with "function" instead of "const".

Hansihe showed:

((module, __webpack_exports__, __webpack_require__) => {
    module.exports = async () => {
        [...]
        __webpack_require__.d(__webpack_exports__, {
            [...],
            "__wbindgen_throw": () => __wbindgen_throw,
        });
        [...]

        var _my_rust_bg_wasm__WEBPACK_IMPORTED_MODULE = __webpack_require__(119);
        _my_rust_bg_wasm__WEBPACK_IMPORTED_MODULE = await Promise.resolve(_my_rust_bg_wasm__WEBPACK_IMPORTED_MODULE);

        [...]

        const __wbindgen_throw = function([..]) { [..] };

        [...]
        return __webpack_exports__;
    }();
})

Webpack tries to export "__wbindgen_throw", but "__wbindgen_throw" is undefined because "__wbindgen_throw" is declared below with "const" and undefined will be exported.

        __webpack_require__.d(__webpack_exports__, {
            [...],
            "__wbindgen_throw": () => __wbindgen_throw,
        });

Now webpack start to load .wasm, but imported object "__wbindgen_throw" is undefined, which leads silent promise rejection.

        var _my_rust_bg_wasm__WEBPACK_IMPORTED_MODULE = __webpack_require__(119);

"__wbindgen_throw" will be hoisted and it is not "undefined" when webpack exports "__wbindgen_throw".

        __webpack_require__.d(__webpack_exports__, {
            [...],
            "__wbindgen_throw": () => __wbindgen_throw,
        });
        [...]
        function __wbindgen_throw([..]) { [..] };

@alexcrichton
Copy link
Contributor

Sorry for the delay in getting to this but thanks for the PR!

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

Successfully merging this pull request may close these issues.

2 participants