This seems like just a normal module and export, not sure what's causing this.
myES6Module.js
const showCar = () => {
//...code
}
const drive = () => {
//...code
};
drive();
export { drive, showCar }
What's weird is in my tests I'm able to import and call these just fine and my tests use them and pass. But when I actually run the drive() which runs the app by prompting the user for terminal input, I get an error saying:
SyntaxError: Unexpected token export
at new Script (vm.js:74:7)
at createScript (vm.js:246:10)
at Proxy.runInThisContext (vm.js:298:10)
at Module._compile (internal/modules/cjs/loader.js:670:28)
Why would this resolve just fine for test but not live running of the code?
Here's how I'm running it, a script in my package.json:
"start": "node --experimental-modules ./myES6Module.js"
so it's when I run yarn start
I get this. Otherwise, when I run my tests, drive() outputs to the console just fine.
if I comment out that exports, my script runs fine...but of course that breaks my tests which rely on exporting stuff.
UPDATE
I'm using --experimental-modules
So I tried this since I have babel-cli installed:
"start": "babel ./myES6Module.js"
package.json has the following babel packages:
"@babel/cli": "^7.0.0-beta.51",
"@babel/preset-env": "^7.0.0-beta.51",
"@babel/register": "^7.0.0-beta.51",
"@babel/core": "^7.0.0-beta.51",
but that just console.logged the file content, it didn't run it.
I don't want to use --experimental-modules
either. I don't want to change my file extension so how do I get this running?
I took a look at this and it mentions about migrating if you are already using babel-node but is that the only way?