将 plugin-proposal-class-properties 添加到 create-react-app 项目中

4

我使用 create-react-app 创建了一个React项目。 现在,在package.json中添加某个依赖项后,在运行npm start之后会收到一个错误消息:

Support for the experimental syntax 'classProperties' isn't currently enabled.
Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.

我尝试使用npm run eject,然后执行npm install --save-dev @babel/plugin-proposal-class-properties,但即使我在package.json中更新了babel部分,它也不起作用:

"babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      "@babel/plugin-proposal-class-properties"
    ]
}

我错过了什么?我在这个论坛上尝试了已经提出的解决方案,但它们都没有起作用。谢谢。

1个回答

0
你可以使用 react-app-rewired 来覆盖 webpack。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接