javascript Babel 节点不会在预设环境上转换扩展运算符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49301610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Babel-node doesn't transform spread operator on preset env
提问by Philip Feldmann
I'm trying to use babel-node with nodemon for the hot-reloading. I've basically followed this repo.
我正在尝试使用 babel-node 和 nodemon 进行热重载。我基本上遵循了这个repo。
My devscript in package.jsonlooks like that:
我的dev脚本package.json看起来像这样:
"dev": "nodemon app.js --exec babel-node --presets env"
My .babelrc:
我的.babelrc:
{
"presets": ["env"]
}
Even though the spread operator is listed as supported by the env preset, when using it with this setup I get a
即使扩展运算符被列为 env 预设支持,但在此设置中使用它时,我得到一个
SyntaxError: Unexpected token
语法错误:意外的令牌
回答by Roberto Alicata
Install https://babeljs.io/docs/plugins/transform-object-rest-spread/
安装https://babeljs.io/docs/plugins/transform-object-rest-spread/
npm install --save-dev @babel/plugin-proposal-object-rest-spread
then change your .babelrc file:
然后更改您的 .babelrc 文件:
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-object-rest-spread"]
}

