我一直在网上搜索,但在任何地方都找不到提到的这种情况,尽管这种情况肯定并不少见。
我一直将create-react-app (版本3.4.x)与react-app-rewired一起使用,主要是为了在不弹出的情况下启用装饰器支持(针对MobX)。
我最近尝试按照说明将cra升级到最新版本(4.0),运行以下命令:
yarn add --exact react-scripts@4.0.0然而,现在当启动我的React服务器时,我得到了这个错误:
yarn start
yarn run v1.22.5
$ HTTPS=true BROWSER=none react-app-rewired start --env=local
Cannot read property 'use' of undefined
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.如果我删除react-app-rewired并将启动脚本改回使用react-scripts,服务器将启动,但我不再支持装饰器。
问题:react-app-rewired支持cra 4.0吗?有没有替代方案可以在不弹出的情况下启用装饰器?感谢您的任何意见!
发布于 2020-11-11 04:52:25
我对rewired没有答案,但是在MobX 6中有一个新东西,可能会让你完全放弃装饰器,makeAutoObservable
import { makeAutoObservable } from "mobx"
class Store {
// Don't need decorators now
string = 'Test String';
setString = (string) => {
this.string = string;
};
constructor() {
// Just call it here
makeAutoObservable (this);
}
}有关更多信息,请单击此处https://mobx.js.org/migrating-from-4-or-5.html和https://mobx.js.org/react-integration.html
https://stackoverflow.com/questions/64776046
复制相似问题