我创建了一个使用类型记录的硬帽项目。当我试图从intellij运行测试时,我得到了:
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运行:

但后来得到了:
× 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调试测试?
顺便说一句,这是测试文件:

发布于 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运行配置中设置环境变量应该可以解决问题。
发布于 2023-02-16 06:45:18
我发现,对我来说,调试硬帽子类型-脚本测试的问题通过以下步骤得到了解决:
Intellij将自动创建配置,如下所示。注意,额外的Mocha选项是空的。肯定是空的。如果它不是空的,那么您就在错误的位置创建了.mocharc.yaml。

发布于 2023-05-11 16:49:33
我能够通过将这2行添加到Module '"hardhat"' has no exported member 'ethers'中来解决tsconfig.json错误:
"include": ["./scripts", "./test", "./typechain-types"],
"files": ["./hardhat.config.ts"]我还需要添加.mocharc.yaml (包含一些内容),但这是为了修复另一个错误。这里有更多详细信息:https://github.com/KartanHQ/intellij-hardhat/issues/196
https://ethereum.stackexchange.com/questions/115395
复制相似问题