3

I've been searching the Web and can't find this situation mentioned anywhere, although it must be not uncommon.

I've been using create-react-app (version 3.4.x) with react-app-rewired [primarily in order to enable decorator support (for MobX) without ejecting].

I recently tried to upgrade cra to the latest version (4.0), following the instructions, by running this command:

yarn add --exact react-scripts@4.0.0

However, now when starting my React server, I get this error:

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.

If I remove react-app-rewired and change the start script back to using react-scripts, the server starts but I don't have decorator support anymore.

Questions: Does react-app-rewired support cra 4.0? Is there an alternative solution for enabling decorators without ejecting? Thanks for any input!

mjh
  • 3,508
  • 3
  • 19
  • 19

1 Answers1

1

Don't have an answer for rewired stuff, but in MobX 6 there is new thing that will probably allow you to drop decorators altogether, 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);
  }
}

More info here https://mobx.js.org/migrating-from-4-or-5.html and https://mobx.js.org/react-integration.html

Danila
  • 15,606
  • 2
  • 35
  • 67
  • Thank you, this is helpful and the direction we might have to go in. I thought decorators were pretty cool, though. – mjh Nov 10 '20 at 23:13