![](/img/trans.png)
[英]Enable spread operator using babel/preset-env in node application
[英]@babel/preset-env version 7 not transforming the null-coalescing operator
我正在使用 typescript 和 babel 设置一个新的节点项目。
我正在使用@babel/preset-env
和@babel/preset-typescript
typescript,这是我的babel.config.js
文件:
module.exports = {
presets: [
[
"@babel/preset-env",
{
targets: {
node: "current",
},
},
],
"@babel/preset-typescript",
],
plugins: [
],
};
在我的代码中,我使用空合并运算符 ( x = a?? b
)。
不幸的是,我收到一个错误,因为无法识别空合并语法,所以Jest encountered an unexpected token
。
@babel/preset-env
版本 7 不应该默认包含它吗? 我的目标是节点 10。
使用babel/plugin-proposal-nullish-coalescing-operator
修复了错误,但我认为这不是必需的。
据我所知,babel preset-env
不支持stage-x
插件。 这个babel/plugin-proposal-nullish-coalescing-operator
目前似乎处于stage-4
,这意味着你必须继续使用它作为插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.