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

如何让VSCode调试器在Hardhat Task的setAction回调断点处暂停?

问题原因与解决方案

核心问题

你当前的调试配置没有告诉Hardhat要执行哪个任务,导致Hardhat只是加载了DoSomething.js里的任务注册代码,却从未执行setAction里的回调逻辑,自然不会触发断点,调试器加载完任务就直接退出了。你猜测的“action被注册为副本”并不是真实原因。

修正后的launch.json配置

把任务名称DoSomething加到runtimeArgs的末尾,同时调整参数顺序(Hardhat的命令格式是hardhat [全局选项] <任务名> [任务参数]):

"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Debug Do Something",
        "skipFiles": [
            "<node_internals>/**"
        ],
        "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/hardhat",
        "runtimeArgs": ["--network", "goerli", "DoSomething", "--account", "0xMyAddress1234555....."]
    }
]

额外注意事项

  • 确保你的任务文件已经被Hardhat识别:要么在hardhat.config.js里手动导入该任务,要么把文件放在项目根目录的tasks文件夹下(Hardhat会自动加载这个目录下的所有任务文件)。
  • 重启调试器后,Hardhat会先加载任务,然后执行DoSomething任务对应的setAction回调,此时你设置的断点就能正常触发了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 13:50:18