2

I am just trying to run a few shticks with javascript to learn more stuff and when I try to import a class it returns Unexpected token {

vehicle.js

export class Vehicle{
  constructor(){

  }
  engineTypeSetter(engine){
    this.engineType = engine;
  }
  wheelNumberSetter(number){
    this.wheelNumber = number;
  }
};

car.js

import {Vehicle} from './vehicle';

class Car extends Vehicle{
  constructor(id){
    super();
    this.id = id;
  }
  idGetter(){
    return this.id;
  }
}
let car = new Car(123);
console.log(car.idGetter());

What am I doing wrong?

  • Node v10.13.0
  • IDE IntelliJ PHPStorm 2018.2.6
clusterBuddy
  • 1,523
  • 12
  • 39
  • So is this like an ego/politics issue? why so many versions need to pass until this gets as a feature? – clusterBuddy Mar 16 '19 at 13:43
  • You are using ES6 modules, you need to use `require` function and export it with `module.exports`. Or run your script with `node --experimental-modules my-app.mjs` – Ertan Kara Mar 16 '19 at 13:46

0 Answers0