The wasm*-unknown-unknown targets are not supported by default, you may need to enable the "js" feature

Hi

I am trying to get lox-wasm running to contribute to the Tor Project.

I followed the README.md and executed wasm-pack build --target web but I get the following errors:

rror: the wasm*-unknown-unknown targets are not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
   --> /Users/niel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.16/src/lib.rs:346:9
    |
346 | /         compile_error!("the wasm*-unknown-unknown targets are not supported by \
347 | |                         default, you may need to enable the \"js\" feature. \
348 | |                         For more information see: \
349 | |                         https://docs.rs/getrandom/#webassembly-support");
    | |________________________________________________________________________^

   Compiling wasm-bindgen v0.2.100
error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> /Users/niel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.16/src/lib.rs:402:9
    |
402 |         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` (lib) due to 2 previous errors

But wasm_js is set for get_random in the Cargo.toml.

It compiles with cargo build --lib --release but that of course does not generate the correct WASM files IG.

My rustc version:

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: aarch64-apple-darwin
release: 1.83.0
LLVM version: 19.1.1

What am I missing?

Edit: Also weird, the Cargo.toml specifies v0.3.0 for get_random, but the error output seems to be working with v0.2.16 :thinking:

├── getrandom v0.3.3
│   │   │   │   │   └── getrandom v0.2.16

it is probably a transitive dependency by other packages, you can check the inverse dependency chain with cargo tree:

$ cargo tree -i get_random@0.2.16

btw, if you omit the version specifier, cargo will prompt you with the different versions.

1 Like

cargo tree -i getrandom@0.2.16 outputs:

etrandom v0.2.16
└── rand_core v0.6.4
    ├── crypto-common v0.1.6
    │   ├── aead v0.5.2
    │   │   └── aes-gcm v0.10.3
    │   │       └── lox-library v0.3.0 (/Users/niel/RustProjects/lox/crates/lox-library)
    │   │           ├── lox-wasm v0.1.0 (/Users/niel/RustProjects/lox/crates/lox-wasm)
    │   │           └── lox_utils v0.3.0 (/Users/niel/RustProjects/lox/crates/lox-utils)
    │   │               └── lox-wasm v0.1.0 (/Users/niel/RustProjects/lox/crates/lox-wasm)
    │   ├── cipher v0.4.4
    │   │   ├── aes v0.8.4
    │   │   │   └── aes-gcm v0.10.3 (*)
    │   │   ├── aes-gcm v0.10.3 (*)
    │   │   └── ctr v0.9.2
    │   │       └── aes-gcm v0.10.3 (*)
    │   ├── digest v0.10.7
    │   │   ├── curve25519-dalek v4.1.3
    │   │   │   ├── ed25519-dalek v2.1.1
    │   │   │   │   └── lox-library v0.3.0 (/Users/niel/RustProjects/lox/crates/lox-library) (*)
    │   │   │   ├── lox-library v0.3.0 (/Users/niel/RustProjects/lox/crates/lox-library) (*)
    │   │   │   └── lox-zkp v0.8.4
    │   │   │       ├── lox-library v0.3.0 (/Users/niel/RustProjects/lox/crates/lox-library) (*)
    │   │   │       └── lox-wasm v0.1.0 (/Users/niel/RustProjects/lox/crates/lox-wasm)
    │   │   ├── sha1 v0.10.6
    │   │   │   └── lox-library v0.3.0 (/Users/niel/RustProjects/lox/crates/lox-library) (*)
    │   │   └── sha2 v0.10.9
    │   │       ├── ed25519-dalek v2.1.1 (*)
    │   │       └── lox-library v0.3.0 (/Users/niel/RustProjects/lox/crates/lox-library) (*)
    │   └── universal-hash v0.5.1
    │       └── polyval v0.6.2
    │           └── ghash v0.5.1
    │               └── aes-gcm v0.10.3 (*)
    ├── curve25519-dalek v4.1.3 (*)
    ├── ed25519-dalek v2.1.1 (*)
    ├── merlin v3.0.0
    │   └── lox-zkp v0.8.4 (*)
    ├── rand v0.8.5
    │   ├── lox-library v0.3.0 (/Users/niel/RustProjects/lox/crates/lox-library) (*)
    │   ├── lox-zkp v0.8.4 (*)
    │   └── lox_utils v0.3.0 (/Users/niel/RustProjects/lox/crates/lox-utils) (*)
    └── rand_chacha v0.3.1
        └── rand v0.8.5 (*)

@nerditation Hmmm, changing my Cargo.toml with this:
getrandom = { version = "0.2", features = ["js"] } instead of getrandom = { version = "0.3.0", features = ["wasm_js"] } seems to compile :thinking:

so the dependency on getrandom@0.2 mostly is traced back to the one of the lox-xxx crates. unless you need the new features from 0.3, it is good practice to stick with the same 0.2 version.

when you change the direct dependency from 0.3 to 0.2, cargo will be able to unify the features since they fall in the same semver number.

1 Like