You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加Tokio依赖后无法构建Dioxus项目,报mio编译错误

Dioxus项目添加Tokio依赖后编译失败问题

场景

在Dioxus项目中添加Tokio依赖,配置如下:

tokio = { version = "1.37.0", features = ["full"] }

编译错误

编译时触发mio库的错误,核心报错如下:

error[E0599]: no method named deregister found for struct IoSource<std::net::UdpSocket> in the current scope
--> /Users/xy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.11/src/net/udp.rs:635:20
|
635 | self.inner.deregister(registry)
| ^^^^^^^^^^ method not found in IoSource<UdpSocket>
|
::: /Users/xy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.11/src/io_source.rs:62:1
|
62 | pub struct IoSource {
| ---------------------- method deregister not found for this struct

Some errors have detailed explanations: E0412, E0425, E0432, E0433, E0599.
For more information about an error, try rustc --explain E0412.
error: could not compile mio (lib) due to 44 previous errors

已尝试无效操作

执行cargo clean和cargo update命令,问题未解决

解决方案

1. 排查并修复mio版本冲突

问题本质是mio库版本不兼容:Tokio的full特性可能引入了与Dioxus依赖的mio版本不一致的包,导致编译时方法找不到。

  • 执行cargo tree -p mio查看项目中mio的所有版本,确认是否存在多版本共存的情况。
  • 在Cargo.toml中强制锁定mio版本为报错中的0.8.11:
mio = "0.8.11"

2. 缩减Tokio的features范围

避免使用full特性,只引入项目实际需要的Tokio功能,减少依赖冲突概率。例如:

tokio = { version = "1.37.0", features = ["rt-multi-thread", "net", "time"] }

3. 匹配Dioxus与Tokio的兼容版本

查看当前使用的Dioxus版本对应的Tokio依赖范围,调整自己的Tokio版本以匹配。例如,如果Dioxus依赖Tokio 1.30+,可尝试将Tokio版本降至1.30.0测试。

内容的提问来源于stack exchange,提问作者xy01

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 18:52:55