7

I'm attempting to implement a custom pallet, but I keep running into this compile error:

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/jackson/.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/jackson/.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`

I have found a few other posts related to this but I haven't found an answer with a connection to the pallets. If I omit the custom pallet, then everything builds fine. Has anyone seen this issue before?

1
  • Fyi if you want to compile the runtime dir directly then cargo check --target=wasm32-unknown-unknoun --no-default-features gets rid of the js error.
    – Squirrel
    Apr 26, 2023 at 11:20

5 Answers 5

11

Pallets compile to WASM which means that all dependencies need to work in a no-std environment.
In your case it looks like one of your dependencies tries to generate random numbers.
This does not work in WASM and the dependency therefore prints that it cannot build.
There are a few cases where this can easily be fixed:

  • Add the dependency as dev dependency if you only need it in tests.
  • Use the proper way to generate randomness on-chain.
  • Use cargo tree to find out how the randomness dependency ends up in your pallet if you don't intend to use it.
  • Analyze the offending dependency and see if it even supports no-std.

In any way; it always helps if you share the code. But hopefully this gives you a hint!

1
  • 1
    It turns out that I had a dependency spelt incorrectly. I had looked through the entire tree searching for the problem and couldn't find it. If anyone is coming across a similar problem make sure that the dependancies are correctly implemented. Aug 12, 2022 at 20:34
2

I've just solved the same issue. In my case it was an extra dependency in a custom pallet. After removing frame-benchmarking = { version = "4.0.0-dev", path = "../../frame/benchmarking" } from Cargo.toml it compiled.

2

Make sure your newly added substrate dependency have default-features = false

0

If you are sure that your std configuration is correct.

Take a look at https://github.com/paritytech/substrate/pull/10837. You may need to cherry-pick this one.

0

Removing Cargo.lock file and changing optional = true to false in Cargo.toml frame-benchmarking's entry worked for me.

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.