I am getting the following Babel error

The decorators Plugin when .version is '2018-09' or not specified, requires a 'decoratorsBeforeExport' option, whose value must be a boolean. ..../node_modules/@babel/plugin-proposal-decorators/lib/index.js$inerhits

This is my babel.config.js

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    'react-native-reanimated/plugin',
    [
        "@babel/plugin-proposal-decorators", 
        { 
            "legacy": true, 
            "decoratorsBeforeExport": false // I tried this with true as well -> no luck either
        }
    ]
 ]
};

This are the versions I am using

    ....
"dependencies": {
    "react": "17.0.2",
    "react-native": "0.66.4"
    ...

"devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/plugin-proposal-decorators": "^7.17.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "7.14.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.66.2",
    ...
4

There are 4 best solutions below

1
On

Try this. It worked for me

module.exports = {
    presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
    plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]]

};

0
On

Make sure to re-run your project when you add these lines. Hot reloading won't work here. Also, it's good to run $ watchman watch-del-all and npm start -- --reset-cache

2
On

That error used to be related to an issue on how you installed your '@babel/plugin-proposal-decorators'. Try to reinstall it as a regular dependency, not dev dependency.

More information here: https://github.com/electron-userland/electron-webpack/issues/251#issuecomment-504693323

0
On

Specify the version at the plugin to support modern decorators, see docs for all versions.

[
    "@babel/plugin-proposal-decorators",
    {
        "version": "2023-05"
    }
]