gpt4 book ai didi

javascript - Node.js 4.2.1 中的导出和导入

转载 作者:行者123 更新时间:2023-11-28 18:53:01 24 4
gpt4 key购买 nike

我有两个文件。

其他.js

export var test = 12;
export var test2 = 'testing';

main.js

import other from "other.js";
console.log(other);

我写node main.js 。我希望这样:

{
test: 12,
test2: 'testing'
}

但是我收到一个错误:

(function (exports, require, module, __filename, __dirname) { import oth from "other.js";
^^^^^^

SyntaxError: Unexpected reserved word

Node.js 版本 4.2.1。怎么了?

最佳答案

Node 不支持导入导出(还吗?谁知道呢)。请参阅https://nodejs.org/en/docs/es6/查看支持功能列表。

您要么需要继续使用 CommonJS 模块,要么使用转换器,例如 Babel .

关于javascript - Node.js 4.2.1 中的导出和导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34161970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com