【发布时间】:2020-08-23 11:55:49
【问题描述】:
我正在尝试将 myArr 从 hello.js 导入到 index.js。但是我得到一个错误
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
文件 hello.js
export let myArr = ['hello', 'hi', 'hey'];
文件 index.js
import { myArr } from './hello.js';
console.log(myArr);
我哪里错了?
【问题讨论】:
-
什么版本的node.js?如果您的文件没有文件扩展名
.mjs,那么您必须做一个whole set of rules 才能让import和export在node.js 中工作。当我尝试它时,我发现它非常痛苦。我相信有一天它只是内置且易于使用,但 node.js 还没有。
标签: javascript node.js