React-MobX Error: The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean

The error message is a little bit confusing however with some little bit deep searching, you can resolve it using the following approach.

I make no assumptions, except that you are using webpack in this guide.

You need to add babel proposal decorators to your dev dependencies (You only need it during dev time) (which you have added already).

if using yarn

yarn add --dev @babel/plugin-proposal-decorators 

otheriwse for npm

npm install --save-dev @babel/plugin-proposal-decorators 

then in your package.json file, locate babel config section or add one if not there. The config name is strictly "babel".

  "babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      [
        "@babel/plugin-proposal-decorators",
        {
          "legacy": true
        }
      ]
    ]
  }

Pay extra attention to the indentation if typing it by hand. notice the object "@babel/plugin-proposal-decorators" is deeply nested inside two arrays, so it has to be as such to work.

and just for sanity check, your devDependencies would at a minimum be as

  "devDependencies": {
    "@babel/plugin-proposal-decorators": "^7.1.2"
  }

Now you can build your application with either yarn or npm and live happily ever after.


React native 0.59

babel.config.js:

{ 
  "presets": ["module:metro-react-native-babel-preset"],
  "plugins": [
        ["@babel/plugin-transform-flow-strip-types"],
        ["@babel/plugin-proposal-decorators", { "legacy": true}],
        ["@babel/plugin-proposal-class-properties", { "loose": true}]
    ]
}

npm install @babel/plugin-transform-flow-strip-types @babel/plugin-proposal-decorators @babel/plugin-proposal-class-properties --save

Source: https://github.com/facebook/react-native/issues/20588#issuecomment-448218111