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

Substrate添加Nicks Pallet后执行cargo check编译报错如何解决?

问题核心原因

报错本质是依赖版本不匹配:你使用的substrate node template是2021-09的月度版本,但引入pallet-nicks时没有指定和本地框架一致的版本,导致Cargo拉取了最新版本的pallet,和现有runtime依赖的substrate核心库版本冲突,才会出现重复lang项、trait实现不匹配等大量报错。

解决步骤

  • 修正runtime/Cargo.toml里的pallet-nicks依赖声明
    将pallet-nicks的版本、git分支/commit配置改成和项目内其他substrate pallet(比如frame-support、frame-system)完全一致的配置,不要使用默认最新版本。
    参考配置示例:
    如果你项目内原有pallet依赖是这样写的:
    frame-support = { version = "3.0.0-monthly-2021-09", git = "https://github.com/paritytech/substrate.git", branch = "monthly-2021-09", default-features = false }
    
    那pallet-nicks也要对应写成:
    pallet-nicks = { version = "3.0.0-monthly-2021-09", git = "https://github.com/paritytech/substrate.git", branch = "monthly-2021-09", default-features = false }
    
    同时不要漏了在runtime/Cargo.toml的[features]段的std列表里加上pallet-nicks/std。
  • 锁定匹配的Rust工具链版本
    2021-09的月度版本substrate需要对应时期的nightly工具链,在项目根目录执行以下命令即可锁定:
    rustup override set nightly-2021-09-30
    rustup target add wasm32-unknown-unknown --toolchain nightly-2021-09-30
    
  • 清理缓存重新执行检查
    cargo clean
    rm Cargo.lock
    cargo check -p node-template-runtime
    

额外说明

你看到的unused doc comment警告不影响编译,把写在construct_runtime!宏上面的三斜杠文档注释改成普通双斜杠注释即可消除该警告。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 04:57:01