-2

I am very much new to ES6, and have wrote a sample class code in node.js using webstorm ide.

'user strict';

class PersonClass {
    constructor(name) {
        this.name = name;
    }

    sayName() {
        console.log(this.name);
    }
}

let person = new PersonClass('My Name');
person.sayName();

When I run the code it displays an error

class PersonClass {
^^^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:974:3

Even though I have installed babel-cli, babel-presets-es2015. How can I fix it.

JN_newbie
  • 5,492
  • 14
  • 59
  • 97

1 Answers1

0

You have a typo, try writing use strict instead of user strict

Nissa
  • 4,636
  • 8
  • 29
  • 37
Juan Tonina
  • 549
  • 9
  • 15