当前位置: 代码迷 >> 综合 >> create-react-app使用装饰器报错Support for the experimental syntax ‘decorators-legacy‘ isn‘t currently...
  详细解决方案

create-react-app使用装饰器报错Support for the experimental syntax ‘decorators-legacy‘ isn‘t currently...

热度:23   发布时间:2023-12-29 09:13:16.0

create-react-app 使用装饰器报错Support for the experimental syntax ‘decorators-legacy’ isn’t currently…@TOC

使用customize-cra、react-app-rewired

npm install  customize-cra react-app-rewired @babel/plugin-proposal-decorators --save

在项目根目录创建config-overrides.js

const { override, addDecoratorsLegacy } = require('customize-cra');
module.exports = override(addDecoratorsLegacy());

修改package.json的scripts

"scripts": {"start": "react-app-rewired start","build": "react-app-rewired build","test": "react-app-rewired test","eject": "react-app-rewired eject"},
  相关解决方案