Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SyntaxError:node.js webstorm中的块作用域声明_Javascript_Node.js_Ecmascript 6_Es6 Class - Fatal编程技术网

Javascript SyntaxError:node.js webstorm中的块作用域声明

Javascript SyntaxError:node.js webstorm中的块作用域声明,javascript,node.js,ecmascript-6,es6-class,Javascript,Node.js,Ecmascript 6,Es6 Class,我对ES6非常陌生,并使用webstorm ide在node.js中编写了一个示例类代码 'user strict'; class PersonClass { constructor(name) { this.name = name; } sayName() { console.log(this.name); } } let person = new PersonClass('My Name'); person.sayName

我对ES6非常陌生,并使用webstorm ide在node.js中编写了一个示例类代码

'user strict';

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

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

let person = new PersonClass('My Name');
person.sayName();
当我运行代码时,它会显示一个错误

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

即使我已经安装了babel cli,babel-presets-es2015。如何修复它。

如果您有输入错误,请尝试编写
使用strict
而不是
user strict

“user strict”?这里的这个用户显然对拼写没有那么严格-P@deceze我的坏朋友没有注意到这一点。谢谢:)也升级到节点6,这不会成为问题。糟糕,谢谢@Juan