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

Leptos结合Axum开发:wasm-bindgen版本不兼容问题

问题

刚接触Rust和Leptos,对Rust/cargo生态系统不太熟悉。按照Leptos教程搭建基于Axum的新项目,运行cargo leptos watch时遇到wasm-bindgen版本不匹配错误:

Error: at `/Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-leptos-0.1.9/src/compile/front.rs:46:30`

Caused by:
    0: at `/Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-leptos-0.1.9/src/compile/front.rs:111:10`
    1: 
       
       it looks like the Rust project used to create this wasm file was linked against
       version of wasm-bindgen that uses a different bindgen format than this binary:
       
         rust wasm file schema version: 0.2.84
            this binary schema version: 0.2.86
       
       Currently the bindgen format is unstable enough that these two schema versions
       must exactly match. You can accomplish this by either updating this binary or 
       the wasm-bindgen dependency in the Rust project.
       
       You should be able to update the wasm-bindgen dependency with:
       
           cargo update -p wasm-bindgen --precise 0.2.86
       
       don't forget to recompile your wasm file! Alternatively, you can update the 
       binary with:
       
           cargo install -f wasm-bindgen-cli --version 0.2.84
       
       if this warning fails to go away though and you're not sure what to do feel free
       to open an issue at https://github.com/rustwasm/wasm-bindgen/issues!

尝试官方给出的两种方案均无效:

  • 执行cargo update -p wasm-bindgen --precise 0.2.86时报错:
Updating crates.io index
error: failed to select a version for the requirement `wasm-bindgen = "=0.2.84"`
candidate versions found which didn't match: 0.2.86
location searched: crates.io index
required by package `start-axum v0.1.0 (...)`
perhaps a crate was updated and forgotten to be re-vendored?
  • 执行cargo install -f wasm-bindgen-cli --version 0.2.84无报错,但原问题未解决。
解决方案

方案1:手动修改依赖版本统一到0.2.86

项目依赖明确锁定了wasm-bindgen为0.2.84,无法通过cargo update直接覆盖,需手动修改:

  1. 打开项目根目录的Cargo.toml文件
  2. 查找所有包含wasm-bindgen的依赖条目,将版本号从0.2.84修改为0.2.86
  3. 执行命令更新依赖:cargo update -p wasm-bindgen --precise 0.2.86
  4. 清理旧编译产物:cargo clean
  5. 重新运行cargo leptos watch

方案2:更新cargo-leptos到最新版本

旧版cargo-leptos(0.1.9)可能存在兼容性问题,更新后可自动适配版本:

  1. 安装最新版cargo-leptos:cargo install -f cargo-leptos
  2. 清理项目缓存:cargo clean
  3. 重新运行cargo leptos watch

方案3:彻底同步全局cli与项目依赖版本

若项目必须保留wasm-bindgen 0.2.84,确保全局cli版本完全匹配:

  1. 卸载现有wasm-bindgen-cli:cargo uninstall wasm-bindgen-cli
  2. 安装指定版本:cargo install -f wasm-bindgen-cli --version 0.2.84
  3. 清理项目编译产物:cargo clean
  4. 重新运行cargo leptos watch

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 11:03:18