我只是安装babeljs并尝试在file.js中翻译我的测试代码:
"use strict";
class Some {
constructor(text = 'hello from es6') {
console.log(text)
}
}
但是在运行babel file.js --out-file file.compile.js
之后,我在file.compile.js中有相同的内容
接下来我从babel cli usage page尝试示例:
babel-node -e "class Test { }"
我得到错误:
[eval]:1
class Test {}
^^^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at Object.exports.runInThisContext (vm.js:53:16)
at _eval (c:\Users\123\AppData\Roaming\npm\node_modules\babelcli\lib\_babel-node.js:102:26)
at Object.<anonymous> (c:\Users\123\AppData\Roaming\npm\node_modules\babel-cli\lib\_babel-node.js:122:16)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:136:18)
at node.js:972:3
我的配置:
os:windows 10
节点:v5.0.0
npm:3.3.6
babel:6.1.1(babel-core 6.0.20)