Reputation: 3238
I'm trying to play around with Node and some ES6/functional stuff.
Here is two files.
dog.js
const dog = () => {
return {
test: (arg) => console.log("dog say: " + arg)
}
}
export default dog;
1.js
import dog from './dog';
const d = dog()
d.test('111');
Node version - 10.4.0 (Node settings are fine)
When I'm running node 1.js
- getting error Unexpected identifier
, pointing on dog. What is wrong here?
P.S. 1.js was updated for proper usage of imported function, but even after that I'm still getting errors.
Upvotes: 4
Views: 5956
Reputation: 25002
Your code works, it logs:
dog say: 111
However, ECMAScript Modules are Experimental in node v10.4.0.
You'll need to run node with the --experimental-modules
flag/option. For example
node --experimental-modules 1.js
Also see the note regarding .mjs extension for module file(s). So you'll probably need to change 1.js
to:
// Note the .mjs extension
import dog from './dog.mjs';
const d = dog()
d.test('111');
Upvotes: 2