reqwest: Getting "unresolved import `crate::sys::IoSourceState`" error running `wasm-pack build` on a project with reqwest/tokio dependencies
I added reqwest/tokio as a dependency to a webassembly project created via wasm-pack-template. When I built the project using wasm-pack build command, it is giving me a long list of errors while compiling mio v0.7.13.
The documentation for reqwest suggests that it support’s WASM so I am confused why the target “wasm32-unknown-unknown” is failing. I can guess it is because the mio’s socket usage (udp/tcp) may not have an equivalent on the browser api but is there any alternate way of building reqwest that would build successfully by using browser’s fetch ?
Steps to reproduce:
cargo generate --git https://github.com/rustwasm/wasm-pack-templateand create asampleproject.- Cd into the
sampleproject - Update Cargo.toml dependencies below:
wasm-bindgen = "0.2.63" // added as part of cargo generate
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
- Run
wasm-pack build(full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown") - Rust version -
rustc 1.53.0 (53cb7b09b 2021-06-17)
Partial Error below (since the errors list is huge):
$ wasm-pack build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Compiling mio v0.7.13
Compiling idna v0.2.3
Compiling wasm-bindgen-backend v0.2.74
Compiling tokio-macros v1.3.0
error[E0432]: unresolved import `crate::sys::IoSourceState`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/io_source.rs:12:5
|
12 | use crate::sys::IoSourceState;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ no `IoSourceState` in `sys`
error[E0433]: failed to resolve: could not find `Selector` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/poll.rs:354:18
|
354 | sys::Selector::new().map(|selector| Poll {
| ^^^^^^^^ could not find `Selector` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:24:14
|
24 | sys::event::token(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:29:14
|
29 | sys::event::is_readable(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:34:14
|
34 | sys::event::is_writable(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:59:14
|
59 | sys::event::is_error(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:90:14
|
90 | sys::event::is_read_closed(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:120:14
|
120 | sys::event::is_write_closed(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:142:14
|
142 | sys::event::is_priority(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:164:14
|
164 | sys::event::is_aio(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:174:14
|
174 | sys::event::is_lio(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/event/event.rs:212:26
|
212 | sys::event::debug_details(f, self.0)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/listener.rs:91:18
|
91 | sys::tcp::accept(inner).map(|(stream, addr)| (TcpStream::from_std(stream), addr))
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:22:15
|
22 | sys: sys::tcp::TcpSocket,
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:53:14
|
53 | sys::tcp::new_v4_socket().map(|sys| TcpSocket { sys })
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:60:14
|
60 | sys::tcp::new_v6_socket().map(|sys| TcpSocket { sys })
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:73:14
|
73 | sys::tcp::bind(self.sys, addr)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:82:27
|
82 | let stream = sys::tcp::connect(self.sys, addr)?;
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:92:29
|
92 | let listener = sys::tcp::listen(self.sys, backlog)?;
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:101:14
|
101 | sys::tcp::set_reuseaddr(self.sys, reuseaddr)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:106:14
|
106 | sys::tcp::get_reuseaddr(self.sys)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:125:14
|
125 | sys::tcp::set_linger(self.sys, dur)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:130:14
|
130 | sys::tcp::get_linger(self.sys)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:135:14
|
135 | sys::tcp::set_recv_buffer_size(self.sys, size)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:159:14
|
159 | sys::tcp::get_recv_buffer_size(self.sys)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:164:14
|
164 | sys::tcp::set_send_buffer_size(self.sys, size)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:188:14
|
188 | sys::tcp::get_send_buffer_size(self.sys)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:195:14
|
195 | sys::tcp::set_keepalive(self.sys, keepalive)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:200:14
|
200 | sys::tcp::get_keepalive(self.sys)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:242:14
|
242 | sys::tcp::set_keepalive_params(self.sys, keepalive)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:260:14
|
260 | sys::tcp::get_keepalive_time(self.sys)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:328:14
|
328 | sys::tcp::get_localaddr(self.sys)
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `tcp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/tcp/socket.rs:334:14
|
334 | sys::tcp::close(self.sys);
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `udp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/udp.rs:122:14
|
122 | sys::udp::bind(addr).map(UdpSocket::from_std)
| ^^^ could not find `udp` in `sys`
error[E0433]: failed to resolve: could not find `udp` in `sys`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.13/src/net/udp.rs:517:14
|
517 | sys::udp::only_v6(&self.inner)
Let me know if you need any other information.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (3 by maintainers)
I think this issue should be reopened
I believe Reqwest will use some Mio features of Tokio if both are imported in the project, and Mio doesn’t work on wasm currently.
So you can add
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]to your cargo.toml file to only import tokio when not compiling for wasm. Reqwest will work without it, as seanmonstar mentions.Similarly to how reqwest does it here: https://github.com/seanmonstar/reqwest/blob/master/Cargo.toml#L100
This file is a great example of dependency management when compiling for various platforms!
In your
[workspace]/[package]configuration, try adding the lineresolver = "2".Resolver 2 is the default in editions 2021 onwards, but it’s possible you have some dependencies with 2018 edition which will make it fallback to version 1
The return type of all functions doesn’t need to be a
JsValue. Only when you want to call that function and use it in JavaScript. If you have multiple functions in Rust that call each other, without JavaScript in the way, you can use Rust return types no problem.