【发布时间】:2018-09-09 16:37:06
【问题描述】:
我正在尝试使用 Babel 在我的项目中启用扩展运算符,但由于 Babel 已删除阶段预设,因此我无法使用扩展运算符:https://www.npmjs.com/package/@babel/plugin-proposal-object-rest-spread
我已经安装了plugin-proposal-object-rest-spread 并将其添加到我的.babelrc:
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-object-rest-spread"
]
}
但我仍然收到以下错误:
Support for the experimental syntax 'objectRestSpread' isn't currently enabled
(28:3):
26 | onClick,
27 | text,
> 28 | ...allProps
| ^
29 | }) => {
30 | let Element = isStatic ? 'span' : renderAs;
31 | const props = modifiers.clean(allProps);
Add @babel/plugin-proposal-object-rest-spread (https://git.io/vb4Ss) to the 'plugins' section of your Babel config to enable transformation.
它建议我添加@babel/plugin-proposal-object-rest-spread。我有,在我的package.json。
有什么想法吗?
【问题讨论】:
-
你的项目目录结构是怎样的,你是怎么称呼 Babel 的?您的
.babelrc文件是否可能被忽略?见babeljs.io/docs/en/config-files#6x-vs-7x-babelrc-loading -
我之前已经解决了,但这是正确的解决方案。作为答案。最初迁移时并不清楚这是一个重要的步骤。很多人都被它的外观绊倒了。
-
@BugHunterUK 您能否通过在此处添加答案来详细说明您的更改?即使阅读他们的文档也无济于事。
标签: babeljs