【问题标题】:Cannot find module 'hardhat/config' or its corresponding type declarations找不到模块 \'hardhat/config\' 或其相应的类型声明
【发布时间】:2022-12-20 13:26:39
【问题描述】:

我正在使用打字稿和纱线建立一个安全帽的新项目。

我正在关注https://hardhat.org/guides/typescript.html,当我到达步骤时“我们需要对您的配置应用三个更改,以便它与 TypeScript 一起工作:" 有一条指令将 hardhat.config.js 更新为 hardhat.config.ts

说明和示例代码说放置import { task } from "hardhat/config";,但 vscode 和编译器说 Cannot find module 'hardhat/config' or its corresponding type declarations.

我错过了什么?

【问题讨论】:

    标签: node.js typescript solidity yarnpkg hardhat


    【解决方案1】:

    也许将此导入添加到您的安全帽配置文件中?

    import { HardhatUserConfig, task } from "hardhat/config";
    

    并小心安装所有必要的类型:

    import "@nomiclabs/hardhat-etherscan";
    import "@nomiclabs/hardhat-waffle";
    import "@typechain/hardhat";
    import "hardhat-gas-reporter";
    import "solidity-coverage";
    

    【讨论】:

      【解决方案2】:

      我也有同样的问题。然后我尝试使用 npm 而不是 yarn 包管理器,错误得到解决。

      我推荐 uninstalling and reinstalling yarn 并检查错误是否得到解决,或者改用 npm 包管理器。

      【讨论】:

        猜你喜欢
        • 2022-12-16
        • 2023-01-31
        • 2020-10-19
        • 2021-09-21
        • 2020-12-23
        • 2020-08-16
        • 2021-02-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多