http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.45k stars 119 forks source link

in v2.3.2 with wasm-client, it could not compile; error[E0432]: unresolved import `http_client::isahc` #345

Open usagi opened 2 years ago

usagi commented 2 years ago

Repro

  1. cargo new surf-wasm-test --lib
  2. edit "Cargo.toml"
    • crate-type = [ "cdylib" ] in [lib]
    • surf = { version = "2.3.2", fefault-features = false, features = [ "wasm-client" ] } in [dependencies]
  3. cargo check --target wasm32-unknown-unknown, and then it occur the error.

Error

    Checking surf v2.3.2
error[E0432]: unresolved import `http_client::isahc`
  --> /home/usagi/.cargo/registry/src/github.com-1ecc6299db9ec823/surf-2.3.2/src/client.rs:13:26
   |
13 |         use http_client::isahc::IsahcClient as DefaultClient;
   |                          ^^^^^ could not find `isahc` in `http_client`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `surf` due to previous error
Fishrock123 commented 2 years ago

Try building with default-features = false, features = ["h1-client"]

usagi commented 2 years ago

Oh, wasm-client is deprecated? Surely, cargo check and cargo test work as expected in surf/wasm-test if modified from wasm-client to h1-client. My problem has been solved thanks to https://github.com/http-rs/surf/issues/345#issuecomment-1130317260 and I can now use the latest version of surf!

But, just in case, this Issue is maybe useful for wasm users who try to use surf newbies and hasn't used it in a long time. Should keep the issue until update the related documents and tests and examples? I will leave it to authors to decide when to close the issue.

Thank you! 💖

Fishrock123 commented 2 years ago

Honestly I wasn't really sure if that would work but cool to know that it did.

KuTuGu commented 1 year ago

Same version and configuration, but didn't work for me, on macOS.

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/bytedance/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.8/src/lib.rs:263:9
    |
263 | /         compile_error!("the wasm32-unknown-unknown target is not supported by \
264 | |                         default, you may need to enable the \"js\" feature. \
265 | |                         For more information see: \
266 | |                         https://docs.rs/getrandom/#webassembly-support");
    | |________________________________________________________________________^

   Compiling foreign-types v0.3.2
   Compiling httparse v1.8.0
error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> /Users/bytedance/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.8/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...
Error: Compilation of your program failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: "cargo" "build" "--tests" "--target" "wasm32-unknown-unknown"