我有一个使用 webpack 设置的 React 应用程序,并且还希望有一个在节点中运行的脚本以将内容写入输出文件,例如:
脚本.mjs
import fs from 'fs';
import {SomeClass} from './index.js';
const outputFile= fs.createWriteStream(__dirname + '/output.png');
// Writes into output file
Run Code Online (Sandbox Code Playgroud)
并在其中包含以下脚本命令package.json
:
"scripts": {
...
"runFile": "node --experimental-modules test/script.mjs",
...
}
Run Code Online (Sandbox Code Playgroud)
每当我运行它时npm run runFile
,它都会抱怨:
import {SomeClass} from './index.js';
^^^^^^^^^
SyntaxError: The requested module './index.js' does not provide an export named 'SomeClass'
Run Code Online (Sandbox Code Playgroud)
即使它存在于该文件中:
./index.js
export SomeClass from './SomeClass';
我什至曾经node -r esm test/script.js
在node中运行,但它一直抱怨ES6 exports
。有人能告诉我如何使用node
命令运行包含 ES6 内容的 js 文件吗?
节点 v10