1.安装依赖
npm install @babel/plugin-proposal-decorators
2.在配置文件package.json文件下配置
"babel": {
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
]
],
"presets": [
"react-app"
]
}
3.如果编译报错 Cannot find module @babel/core:
删除babel-preset-react-native最新版本,并将其版本退回至3.0.2
npm unstall babel-preset-react-native
npm install --save-dev babel-preset-react-native@^3.0.2
4.如果报:Cannot find module ‘babel-preset-react-app’ from …
npm install babel-preset-react-app --save-dev
5.使用eslint的时候装饰器装饰的方法或者类下面会有小红线,解决办法:
在根目录下创建jsconfig.json文件,将下方代码写入;
{
"compilerOptions": {
"experimentalDecorators": true,
"baseUrl": ".",
"paths": {
"@Components/*": ["components/*"],
"@TrialOS/*": ["source/trialOS/components/*"],
"@Collaboration/*": ["source/collaboration/components/*"],
"@Sms/*": ["source/SMS/*"],
"@Assets/*": ["source/resources/*"],
"@Utils/*": ["utils/*"]
},
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": true
}
}
6.重新启动项目。