【问题标题】:Upgrading to create-react-app version 4.0 with react-app-rewired: server start error使用 react-app-rewired 升级到 create-react-app 4.0 版:服务器启动错误
【发布时间】:2021-02-22 19:30:42
【问题描述】:

我一直在网上搜索,在任何地方都找不到提到的这种情况,尽管它一定很常见。

我一直在使用 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?是否有替代解决方案可以在不弹出的情况下启用装饰器?感谢您的任何意见!

【问题讨论】:

  • 嗨@mjh!您找到服务器启动错误的解决方案了吗?
  • 关于这个问题的任何其他更新?

标签: reactjs decorator create-react-app mobx react-app-rewired


【解决方案1】:

对于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.htmlhttps://mobx.js.org/react-integration.html

【讨论】:

  • 谢谢,这对我们很有帮助,也是我们可能必须前进的方向。不过,我认为装饰器很酷。
猜你喜欢
  • 2018-09-16
  • 2020-12-23
  • 1970-01-01
  • 2018-07-21
  • 2018-05-01
  • 2018-07-16
  • 1970-01-01
  • 2021-04-28
  • 2019-07-08
相关资源
最近更新 更多