4

I got this error when building the whole project 'cargo build --release'. But build package works fine 'cargo build -p pallet-template'

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/stefan_muto/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.3/src/lib.rs:219:9
      |
  219 | /         compile_error!("the wasm32-unknown-unknown target is not supported by \
  220 | |                         default, you may need to enable the \"js\" feature. \
  221 | |                         For more information see: \
  222 | |                         https://docs.rs/getrandom/#webassembly-support");
1
  • 1
    This might be an error with feature gating for the wasm runtime build. Did you add any new dependencies? If so make sure the default features are disabled for the new dependencies and then under the std feature of the crate you can add in can enable the std features of the new deps.
    – zekemostov
    Commented Feb 28, 2022 at 22:04

2 Answers 2

-3

As the compiler tips says, just try to modify the cargo.toml file in this way:

[dependencies]
getrandom = { version = "0.2", features = ["js"] }

Try it, dude.

8

As Zeke has alluded to in his comment, this is usually a problem with dependencies that did not have the default-features option set to false. In addition, you'll also need to know how to enable std properly in the [features] section in order to fix this issue properly.

To illustrate, let's say that you want to add a dependency called nicks-pallet. The proper way of including it in the Cargo.toml file is to write it in the following way:

[dependencies]
nicks-pallet = { /* version or git */, default-features = false }

[features]
default = []
std = ["nicks-pallet/std"]
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.