I have a react app set up with webpack, and would like to also have a script that runs in node to write stuff into output file, such as:
script.mjs
import fs from 'fs';
import {SomeClass} from './index.js';
const outputFile= fs.createWriteStream(__dirname + '/output.png');
// Writes into output file
and have the following script command in package.json
:
"scripts": {
...
"runFile": "node --experimental-modules test/script.mjs",
...
}
Whenever I run npm run runFile
it complains with:
import {SomeClass} from './index.js';
^^^^^^^^^
SyntaxError: The requested module './index.js' does not provide an export named 'SomeClass'
even though it exists in that file:
./index.js
export SomeClass from './SomeClass';
I even used node -r esm test/script.js
to run in node, but it keeps complaining about ES6 exports
all the time. Could anybody point me to how to run a js file that has ES6 stuff with node
command?
NODE v10