React - 当前未启用 'classProperties'

React - 'classProperties' isn't currently enabled

我将 Truncate-react 添加到我的项目中。在那之后,React 告诉我我需要安装 @babel/plugin-proposal-class-properties,我在 package.json 文件中是这样安装的:

      "babel": {
        "presets": [
          "@babel/preset-env",
          "@babel/preset-react"
        ],
        "plugins": [
          [
            "@babel/plugin-proposal-class-properties",
            {
              "loose": true
            }
          ]
        ]
      }

当然,我安装的 proposal-class-properties 本身带有标签 --save-dev

但在这之后,我仍然收到类似这样的错误

根据您发送的 github link,您必须做 2 件事才能使其正常工作

  1. 您的 package.json 中同时拥有 .babelrc 文件和 babel 配置。你必须选择一个。
  2. 您必须将 import TextTruncate from 'react-text-truncate/src/TextTruncate' 更改为 import TextTruncate from 'react-text-truncate' 在 VideoCard 组件中。 我假设 react-text-truncate/src/TextTruncate 这个文件不是编译版本