2016-11-21 118 views
-2

我對ES6非常陌生,並且已經使用webstorm ide在node.js中編寫了一個示例類代碼。SyntaxError:node.js中的塊範圍聲明webstorm

'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 

即使我已經安裝了巴貝爾,CLI,巴貝爾,預置-ES2015。我該如何解決它。

+1

「用戶嚴格」?這個用戶在這裏顯然沒有那麼嚴格拼寫...; -P – deceze

+0

@deceze我的壞沒有注意到。謝謝:) –

+0

也升級到節點6,這不會是一個問題。 – loganfsmyth

回答

0

你有一個錯字,嘗試寫的use strict代替user strict

+0

哎呀,我的壞,謝謝@Juan –