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

Where to enable "js" for wasm-bindgen #267

Closed
marvellous987 opened this issue Jun 20, 2022 · 3 comments
Closed

Where to enable "js" for wasm-bindgen #267

marvellous987 opened this issue Jun 20, 2022 · 3 comments
Labels
good first issue Good for newcomers

Comments

@marvellous987
Copy link

Hi, I am trying to compile my program into WebAssembly using wasm-bindgen, but I got the following errors:

error: the wasm32-unknown-unknown target is not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
   --> /Users/xxx/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.7/src/lib.rs:235:9
    |
235 | /         compile_error!("the wasm32-unknown-unknown target is not supported by \
236 | |                         default, you may need to enable the \"js\" feature. \
237 | |                         For more information see: \
238 | |                         https://docs.rs/getrandom/#webassembly-support");
    | |________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> /Users/xxx/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.7/src/lib.rs:262:5
    |
262 |     imp::getrandom_inner(dest)
    |     ^^^ use of undeclared crate or module `imp`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `getrandom` due to 2 previous errors

May I ask where I can enable the "js" feature, as shown in https://docs.rs/getrandom/latest/getrandom/#webassembly-support? Or are there any other solutions?

Thank you!

@vdods
Copy link

vdods commented Jun 24, 2022

You want to enable the "js" feature on the getrandom crate itself. Even if your crate doesn't directly depend on it, you'll want to add a line like
getrandom = { version = "0.2", features = ["js"] }

@josephlr
Copy link
Member

@vdods is correct. We explain this in our docs for the custom feature, but we should also explain how to do it for the js feature, as that is more common.

@newpavlov
Copy link
Member

I think we close this issue considering #280 is merged.

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

No branches or pull requests

4 participants