-
Notifications
You must be signed in to change notification settings - Fork 185
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
This crate hits a buggy Webpack 5 warning when building for wasm32-unknown #224
Comments
In order to tell Webpack 5 to ignore this specific warning you can add the following into your module.exports = {
// ...
ignoreWarnings: [
(warning) =>
warning.message ===
"Critical dependency: the request of a dependency is an expression",
],
// ...
} Naturally this is not the proper fix for the problem; just a work-around in case the warning is producing too much nuisance for you. |
I just opened the PR #234 for addressing this problem. Here's my .02$ on the alternatives listed in the issue description:
|
I think the reason is that webpack needs to know the value upfront, is to apply the correct loader if necessary. Users can define rules based on this value to use specific loaders such as ts-loader for example. There are loaders, for example, that inline the import, replacing it by the contents of the module: https://github.com/facebook/create-react-app/blob/edc671eeea6b7d26ac3f1eb2050e50f75cf9ad5d/packages/react-dev-utils/InlineChunkHtmlPlugin.js I guess If the dependency is an expression, webpack will just leave it as is and skip the loader rules. |
- Use production mode for wasm-pack Development mode results in 'Unexpected section' error, possibly due to unstripped sections in wasm. - Ignore "Critical dependency" warning The problem and the workaround are described in rust-random/getrandom#224
See this comment for context: #137 (comment)
Previous toil on this issue:
Fix in this crate for Webpack 4: #137
Rustwasm bug: rustwasm/wasm-pack#822
Webpack bug closed as WONTFIX: webpack/webpack#8826
Advice on how to fix this issue for Webpack: webpack/webpack#8826 (comment)
Basically, our
#[wasm_bindgen]
declaration generates Javascript that looks like:Despite this being valid JavaScript, Webpack doesn't like it for some reason.
It seems like our options to fix this are:
package.json
stuff I don't understand)wasm_bindgen
tool to annotatemodule.require
with some sort of "ignore warning" requirementimport()
callwasm_bindgen
'smodule
attribute.wasm_bindgen
'sinline_js
attributewasm32-unknown-browser
andwasm32-unknown-node
targets, so that we don't have to do browser vs Node detection at runtime.Things we shouldn't try to do:
eval("require(crypto)")
However, I don't have the expertise to solve this problem. If anyone (@Pauan, @huacnlee , @Herohtar) knows how to fix this issue, I would happily accept a PR provided the solution is documented and our CI keeps passing (we don't use the Webpack bundler in our CI, hence why we missed this).
The text was updated successfully, but these errors were encountered: