我有一个使用webpack搭建的React应用程序,希望同时运行一个在Node中编写输出文件的脚本,例如:
script.mjs
import fs from 'fs';
import {SomeClass} from './index.js';
const outputFile= fs.createWriteStream(__dirname + '/output.png');
// Writes into output file
并且在 package.json
文件中添加以下脚本命令:
"scripts": {
...
"runFile": "node --experimental-modules test/script.mjs",
...
}
每当我运行
npm run runFile
时,它会抱怨:import {SomeClass} from './index.js';
^^^^^^^^^
SyntaxError: The requested module './index.js' does not provide an export named 'SomeClass'
即使它存在于那个文件中:
./index.js
export SomeClass from './SomeClass';
我甚至使用了 node -r esm test/script.js
在 node 中运行,但它一直抱怨 ES6 的 exports
。有人能告诉我如何使用 node
命令运行一个包含 ES6 内容的 js 文件吗?
NODE v10