“use of undeclared crate or module `imp`” on getrandom-0.2.8 when building for wasm32-unknown-unknown
- Dominant language
- Rust
- Stars
- 527
- Forks
- 362
- PR merge metrics
- No merged PRs in 30d
Description
I cloned cw20-base and tried to cargo build-bpf but failed.
This is Cargo.toml
```
[lib]
crate-type = ["cdylib", "rlib"]
[features]
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []
[dependencies]
cosmwasm-schema = "1.2.3"
cosmwasm-std = "1.2.3"
cw-storage-plus = "1.0.1"
cw-utils = "1.0.1"
cw2 = "1.0.1"
cw20 = "1.0.1"
schemars = "0.8.12"
semver = "1.0.17"
serde = { version = "1.0.159", default-features = false, features = ["derive"] }
thiserror = "1.0.40"
[dev-dependencies]
cw-multi-test = "0.16.1"
```
I got error like this
```
error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
--> src/lib.rs:268:9
|
268 | / compile_error!("target is not supported, for more information see: \
269 | | https://docs.rs/getrandom/#unsupported-targets");
| |________________________________________________________________________^
error[E0433]: failed to resolve: use of undeclared crate or module `imp`
--> src/lib.rs:290:5
|
290 | 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
warning: build failed, waiting for other jobs to finish...
```
[Unsupport targets](https://docs.rs/getrandom/latest/getrandom/#unsupported-targets) doesn't work, too.
I added the getrandom dependency mannually `getrandom = { version = "0.2", features = ["js"] }` in Cargo.toml file but its version doesn't change into 0.2.8 in Cargo.lock and the error still happened.
Is there anyone who can help me urgently?
I pulled tons of hairs to solve it for some days.
Contributor guide
Research direction
Start by reproducing the failure with `cargo build-bpf` from the reported cw20-base setup. Inspect `Cargo.toml`, `Cargo.lock`, and the resolved `getrandom` 0.2.8 dependency, including its wasm target configuration. Done means the project builds for `wasm32-unknown-unknown` without the unsupported-target or undeclared `imp` errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, wasm
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100