尝试在带有-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>
有什么想法吗?
最佳答案
移动平均值当前仅具有单个默认导出。您将需要导入整个模块,然后可以选择解构参数。
import movingAverages from 'moving-averages'
const {ma, dma, ema, sma, wma} = movingAverages;