【发布时间】:2022-01-24 09:03:46
【问题描述】:
所以我目前正在使用安全帽上的交易机器人进行练习。我的问题是,当我想运行我的脚本时,会出现这个错误:
import './ABIConstants.js';
^^^^^^
SyntaxError: Cannot use import statement outside a module
有了这个建议:
(node:1284) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
但是,当我按照它告诉我的操作并设置 "type":"module" 时,我收到此错误:
hardhat.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename hardhat.config.js to end in .cjs, change the requiring code to use dynamic import() which is avakage.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
并且错误继续,就像我在上面做的那样......等等......
我该如何解决这个问题?
如果有帮助,这是我用来运行脚本的命令
npx hardhat run scripts/ArbitrageBot.js
【问题讨论】:
-
看来
hardhat.config.js文件正在使用require()? -
@RandyCasburn 是的,我该怎么办?
-
有点忙 - 看起来 jfriend 尽可能地回答了一个好问题。
标签: javascript node.js solidity hardhat