Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.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
Babel对我的Javascript没有影响_Javascript_Ecmascript 6_Babeljs - Fatal编程技术网

Babel对我的Javascript没有影响

Babel对我的Javascript没有影响,javascript,ecmascript-6,babeljs,Javascript,Ecmascript 6,Babeljs,下面是我的polygon.js 类多边形{ 建造商(高度、宽度){ 高度=高度; 这个。宽度=宽度; } getArea(){ 把这个还给我。calcArea() } 钙质(){ 返回this.height*this.width; } } 我跑 babel polygon.js-o output.js cat output.js | pbcopy 粘贴: 类多边形{ 建造商(高度、宽度){ 高度=高度; 这个。宽度=宽度; } getArea(){ 返回这个。calcArea(); } 钙质

下面是我的
polygon.js

类多边形{
建造商(高度、宽度){
高度=高度;
这个。宽度=宽度;
}
getArea(){
把这个还给我。calcArea()
}
钙质(){
返回this.height*this.width;
}
}
我跑

babel polygon.js-o output.js
cat output.js | pbcopy
粘贴:

类多边形{
建造商(高度、宽度){
高度=高度;
这个。宽度=宽度;
}
getArea(){
返回这个。calcArea();
}
钙质(){
返回this.height*this.width;
}
}
我本来希望传输到ES5,但代码保持不变

发生什么事了

$ .babel --version
6.2.0 (babel-core 6.2.1)
编辑:我使用
npm安装babel-preset-2015-g安装了预设

~/es6:.babel polygon.js -o output.js --presets es2015
Error: Couldn't find preset "es2015" relative to directory "."
    at OptionManager.mergePresets (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:327:17)
    at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:287:12)
    at OptionManager.init (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:416:10)
    at File.initOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:190:75)
    at new File (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:121:22)
    at Pipeline.transform (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/pipeline.js:42:16)
    at transform (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:53:22)
    at Object.compile (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:62:12)
    at /usr/local/lib/node_modules/babel-cli/lib/babel/file.js:130:23
    at arrayEach (/usr/local/lib/node_modules/babel-cli/node_modules/lodash/index.js:1289:13)

编辑:-g安装后出现问题。我在本地安装,它可以正常工作。

这也让我感到困惑。Babel的新版本要求您安装一个预置,可能需要在CLI命令中明确指定它

根据Babel的安装位置(全球/本地),您需要在其中安装预设:

npm install babel-preset-es2015
然后你可以跑巴贝尔。例如,这将使用预设将一个文件夹中的所有文件转换为另一个文件夹

babel [srcFolder] --out-dir [outFolder] --presets es2015

这也让我抓狂了。Babel的新版本要求您安装一个预置,可能需要在CLI命令中明确指定它

根据Babel的安装位置(全球/本地),您需要在其中安装预设:

npm install babel-preset-es2015
然后你可以跑巴贝尔。例如,这将使用预设将一个文件夹中的所有文件转换为另一个文件夹

babel [srcFolder] --out-dir [outFolder] --presets es2015

请参阅我编辑的文章,了解我运行该程序时会发生什么。编辑:开始工作了。谢谢你@Andy!嗨,你是如何用巴贝尔7做到这一点的?请看我编辑的文章,了解我运行巴贝尔7时会发生什么。编辑:开始工作了。谢谢你@Andy!嗨,巴贝尔7是怎么做到的?