【发布时间】:2018-07-18 20:37:19
【问题描述】:
尝试在带有 -experimental-modules 标志的节点中使用 ES6 导入。具体来说:
mkdir ma
cd ma
npm init
npm i --save moving-averages
touch index.mjs
现在将以下代码放入 index.mjs 中:
import {
ma, dma, ema, sma, wma
} from 'moving-averages'
ma([1, 2, 3, 4, 5], 2)
结果是:
file:///home/ole/ma/index.mjs:2
ma, dma, ema, sma, wma
^^
SyntaxError: The requested module does not provide an export named 'ma'
at ModuleJob._instantiate (internal/loader/ModuleJob.js:86:19)
at <anonymous>
想法?
【问题讨论】:
-
这个thread from the Node Modules Working Group 解释了为什么来自 CommonJS 模块的命名导入不起作用。
标签: javascript node.js npm