Dioxus应用启动失败:Bindgen版本不兼容问题求助
解决Dioxus应用启动时的Bindgen版本不兼容问题
问题详情
启动新建Dioxus应用时失败,核心错误为Bindgen版本不兼容,具体错误日志如下:
[WARN] Config file: `Dioxus.toml` not found; using default config. [WARN] Config file: `Dioxus.toml` not found; using default config. [INFO] 🚅 Running build command... [INFO] 👑 Build done. [WARN] failed to parse `name` custom section Invalid name type (at offset 30985979) thread 'main' panicked at 'unknown descriptor: 72', C:\Users\asili\.cargo\registry\src\github.com-1ecc6299db9ec823\wasm-bindgen-cli-support-0.2.83\src\descriptor.rs:154:22 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace [ERROR] 🚫 Serve startup failed: Build Failed: Bindgen build failed! This is probably due to the Bindgen version, dioxus-cli using `0.2.81` Bindgen crate.
项目配置文件Cargo.toml:
[package] name = "dioxus-example" version = "0.1.0" edition = "2021" [dependencies] dioxus = "0.3.2" dioxus-web = "0.3.2" wasm-bindgen = "0.2.78"
main.rs代码:
#![allow(non_snake_case)] // import the prelude to get access to the `rsx!` macro and the `Scope` and `Element` types use dioxus::prelude::*; fn main() { // launch the web app dioxus_web::launch(App); } // create a component that renders a div with the text "Hello, world!" fn App(cx: Scope) -> Element { cx.render(rsx! { div { "Hello, world!" } }) }
解决办法
1. 统一项目与dioxus-cli的wasm-bindgen版本
dioxus-cli当前依赖0.2.81版本的wasm-bindgen,而项目中使用的是0.2.78,版本差异引发构建失败。修改Cargo.toml中的wasm-bindgen版本,与cli保持一致:
[dependencies] dioxus = "0.3.2" dioxus-web = "0.3.2" wasm-bindgen = "0.2.81"
2. 更新dioxus-cli至兼容版本
若希望保留项目中的wasm-bindgen版本,可更新dioxus-cli到匹配的最新版本,执行命令:
cargo install dioxus-cli --force
更新完成后重新运行dx serve启动应用。
3. 清理构建缓存后重新构建
执行命令清理旧构建缓存,避免残留的版本冲突文件影响构建:
cargo clean
清理完成后再次运行dx serve尝试启动。
内容的提问来源于stack exchange,提问作者Jose A
相关产品推荐
相关产品推荐

