通过create-react-app创建的react项目配置mobx的时候报的错误,笔者使用的是
"mobx": "^5.15.0",
"mobx-react": "^6.1.4",
一、装包
- npm i customize-cra --save
- npm i react-app-rewired --save
- npm i @babel/plugin-proposal-decorators --save
二、项目根目录新建config-overrides.js文件
const { override, addDecoratorsLegacy } = require('customize-cra');
module.exports = override(
addDecoratorsLegacy()
);
三、修改package.json文件中的script
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},
经过这三步操作之后,mobx就可以美滋滋的使用了