-
Notifications
You must be signed in to change notification settings - Fork 177
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
Module not found: Error: Can't resolve 'env' #263
Comments
You can take a look at the examples to see how to setup a |
If you want your package to work with both https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section [dependencies]
wasm-bindgen = { version = "0.2", optional = true }
console_error_panic_hook = { version = "0.1.1", optional = true }
wee_alloc = { version = "0.4.1", optional = true }
stdweb = { version = "0.4.8", optional = true } This will probably require you to also use #[cfg(feature = "wasm-bindgen")]
fn foo() -> u32 { ... }
#[cfg(feature = "stdweb")]
fn foo() -> u32 { ... } |
Got ya. Thank you @Pauan for the very helpful context and links. |
The workaround is described in webpack/webpack#7352 Note that now the webserver cannot load our wasm: "TypeError: _myelin_visualization_bg__WEBPACK_IMPORTED_MODULE_0__.init is not a function" This might be caused by a transcient dependency on stdweb: https://github.com/sebcrozet/nphysics/blob/master/build/nphysics2d/Cargo.toml#L31 Which is incompatible with wasm-bindgen: koute/stdweb#263
I'm running into an issue trying to build for
wasm32-unknown-unknown
, and not sure exactly where the problem is, so I'll apologize in advance if this is the wrong repo. I'll also apologize in advance for the fairly lengthy issue.If I build a very vanilla Rust project for the web, with the following:
Cargo.toml
lib.rs
And an
index.js
like this:And then build it as follows:
cargo +nightly build --target wasm32-unknown-unknown wasm-bindgen target/wasm32-unknown-unknown/release/jsfrontend.wasm --out-dir .
I get an output file
stdwebtest.js
with the following contents (alongside the other generated artifacts like thewasm
file, etc):And I can use Webpack to serve that and it works as expected (I get an alert saying hello and a console log).
Adding
stdweb
Once I add
stdweb
as a dependency, it breaks.Cargo.toml
lib.rs
And build it the same way, as soon as I try to serve it with Webpack, I get the following:
This has led me to this issue on the Webpack repo webpack/webpack#7388 which links to this issue webpack/webpack#7352.
None of the suggestions in those issues work, and I'm not sure why. Is
stdweb
compiled with Emscripten by default? Is there a way to change that?I've also tried compiling it with
cargo web build --release --target wasm32-unknown-unknown
, and using the generated.js
and.wasm
files it creates, but that has a whole new class of problems.If its helpful I can put up a repository with all info. Any help would be appreciated!
The text was updated successfully, but these errors were encountered: