首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用intellij调试安全帽项目

使用intellij调试安全帽项目
EN

Ethereum用户
提问于 2021-12-11 16:05:31
回答 3查看 1.1K关注 0票数 1

我创建了一个使用类型记录的硬帽项目。当我试图从intellij运行测试时,我得到了:

代码语言:javascript
复制
TSError: ⨯ Unable to compile TypeScript:
test/index.ts(2,10): error TS2305: Module '"hardhat"' has no exported member 'ethers'.

如果我从命令行运行测试,它就会运行得很好:

以下是我的intellij运行配置:

另外,对于javascript项目,一切都很好(我可以使用intellij对其进行调试,没有任何问题),这个问题只发生在一个类型记录硬帽子项目中。

我尝试过安装摩卡-打字本@测试甲板/摩卡,并将intellij配置更改为使用mocha-typescript运行:

但后来得到了:

代码语言:javascript
复制
× ERROR: Error: Could not load ui "mocha-typescript":

 Error: Cannot find module 'C:\Users\Yogev\dev\temp\mocha-typescript'
Require stack:
- C:\NodeNpm\npm\node_modules\mocha\lib\cli\run-helpers.js
- C:\NodeNpm\npm\node_modules\mocha\lib\cli\options.js
- C:\NodeNpm\npm\node_modules\mocha\bin\mocha
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at exports.validateLegacyPlugin (C:\NodeNpm\npm\node_modules\mocha\lib\cli\run-helpers.js:234:27)
    at C:\NodeNpm\npm\node_modules\mocha\lib\cli\run.js:355:9 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\NodeNpm\\npm\\node_modules\\mocha\\lib\\cli\\run-helpers.js',
    'C:\\NodeNpm\\npm\\node_modules\\mocha\\lib\\cli\\options.js',
    'C:\\NodeNpm\\npm\\node_modules\\mocha\\bin\\mocha'
  ]

为什么会这样呢?如何在类型记录项目中使用intellij调试测试?

顺便说一句,这是测试文件:

EN

回答 3

Ethereum用户

发布于 2021-12-14 23:16:36

ts-node不解析项目目录中的所有文件中的类型,这些类型--虽然减少了启动时间--可能导致缺少类型。

若要重写此操作,请尝试添加以下任一项:

  • 指向--files参数的ts-node标志,或
  • TS_NODE_FILES环境变量设置为true

这种行为也在官方的硬帽文档:https://hardhat.org/guides/typescript.html#running-your-tests-and-scripts-directly-with-ts-node中描述过。

在您的情况下,在IntelliJ运行配置中设置环境变量应该可以解决问题。

票数 1
EN

Ethereum用户

发布于 2023-02-16 06:45:18

我发现,对我来说,调试硬帽子类型-脚本测试的问题通过以下步骤得到了解决:

  1. npm -i -D ts-mocha
  2. 在项目根目录:.mocharc.yaml中创建一个文件。本文解释了为什么需要它:https://youtrack.jetbrains.com/issue/WEB-48850#focus=Comments-27-4615521.0-0
  3. 重启Intellij
  4. 从IntelliJ运行测试(单击GUI上的测试并选择Run或debug)

Intellij将自动创建配置,如下所示。注意,额外的Mocha选项是空的。肯定是空的。如果它不是空的,那么您就在错误的位置创建了.mocharc.yaml。

票数 0
EN

Ethereum用户

发布于 2023-05-11 16:49:33

我能够通过将这2行添加到Module '"hardhat"' has no exported member 'ethers'中来解决tsconfig.json错误:

代码语言:javascript
复制
  "include": ["./scripts", "./test", "./typechain-types"],
  "files": ["./hardhat.config.ts"]

我还需要添加.mocharc.yaml (包含一些内容),但这是为了修复另一个错误。这里有更多详细信息:https://github.com/KartanHQ/intellij-hardhat/issues/196

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/115395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档