Iam receiving SyntaxError: Unexpected token import even if my node is v6. What am I missing ? How do I make import Construct from 'can/construct/'; work for me instead of require ?
import Construct from 'can/construct/'; // Doesnt work
var Construct = require('can-construct'); // Works for me
var Animal = Construct.extend({
sayHi: function(){
console.log("hi")
}
});
var animal = new Animal()
animal.sayHi();
I understand I need to be in ES6 to use import statement. But I already have it .
/usr/local/bin/node --version
v6.10.1
not sure package.json matters :
{
"name": "canjstest",
"version": "1.0.0",
"description": "",
"main": "canjs.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "Test",
"dependencies": {
"canjs": "^2.2.0"
}
}
What am I missing ?
ES6 modules are not supported in Node at all. There are some great article (one, two) around why it's been hard to decide how to implement it.
I suggest to transpile your code via babel.
A quick npm script would be:
While you need the following npm modules:
Hope that helps