小编O I*_*uwa的帖子

在node js中导入时加载“ES模块”的问题

所以我目前正在使用安全帽上的交易机器人进行练习。我的问题是,当我想运行我的脚本时,会出现此错误:

    import './ABIConstants.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module
Run Code Online (Sandbox Code Playgroud)

有了这个建议:

(node:1284) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
Run Code Online (Sandbox Code Playgroud)

但是,当我按照它告诉我的那样设置“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() …
Run Code Online (Sandbox Code Playgroud)

javascript node.js solidity hardhat

3
推荐指数
1
解决办法
5145
查看次数

标签 统计

hardhat ×1

javascript ×1

node.js ×1

solidity ×1