Create React App不支持装饰器的解决方案

找到node_modules/babel-preset-react-app/index.js中的这段代码

const plugins = [
  // Necessary to include regardless of the environment because
  // in practice some other transforms (such as object-rest-spread)
  // don't work without it: https://github.com/babel/babel/issues/7215
  // 找到这一行替换 为 require.resolve('babel-plugin-transform-decorators-legacy') 
  require.resolve('babel-plugin-transform-es2015-destructuring'), 
  // class { handleClick = () => { } }
  require.resolve('babel-plugin-transform-class-properties'),
  // The following two plugins use Object.assign directly, instead of Babel's
  // extends helper. Note that this assumes `Object.assign` is available.
  // { ...todo, completed: true }
  [
    require.resolve('babel-plugin-transform-object-rest-spread'),
    {
      useBuiltIns: true,
    },
  ],
  // Transforms JSX
  [
    require.resolve('babel-plugin-transform-react-jsx'),
    {
      useBuiltIns: true,
    },
  ],
  // Polyfills the runtime needed for async/await and generators
  [
    require.resolve('babel-plugin-transform-runtime'),
    {
      helpers: false,
      polyfill: false,
      regenerator: true,
    },
  ],
];

修改babelrc资源配置文件, 添加

{
  ...
  "presets": ["transform-decorators-legacy"]
}

修改package.json资源配置文件, 添加

"babel": {
    "plugins": [
        ....
      "transform-decorators-legacy"
    ]
  }

然后重启服务