bundling failed: Error: Cannot find module 'babel-preset-react-native-stage-0/decorator-support'

Viewed 15165

Getting this error after push and clone from bitbucket, previously existing project running fine, after clone from bitbucket did npm install and .babelrc file exist in the root directory.

{
  "presets": [
    "babel-preset-react-native-stage-0/decorator-support"
  ],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source"
      ]
    }
  }
}

Steps tried :

  • npm install babel-preset-react-native-stage-0 --save
  • npm install --save-dev babel-preset-react-native@2.1.0

But getting same error on the screen.

Screen shot :

enter image description here

5 Answers

I too was getting the same problem while I was trying to run an old react-native project. I am just starting to learn react-native and hence was experimenting with an old project from a colleague.

After reading above answers I finally solved this issue

There were lot of files in the root folder of which two were:

  1. .babelrc
  2. babel.config.js

containing following things:

.babelrc

{ 
 "presets": ["react-native"]
}

babel.config.js

module.exports = {
 presets: ['module:metro-react-native-babel-preset'],
};

I didn't knew either of them. But I tried following above answers and commented out .babelrc contents like this:

{ 
 // "presets": ["react-native"]
}

Then started the server again and it did run as expected.

For me I solved the Issue to remove the second preset:

"presets": [
            "react-native"
          ]

down in the "plugins"-Section:

{
  "presets": ["module:metro-react-native-babel-preset"],
  "env": {
    "production": {
      "plugins": [
        "transform-remove-console",
        "@babel/plugin-proposal-optional-chaining",
        [
          "module-resolver",
          {
            "root": [
              "./src"
            ],
            "alias": {
              "test": "./test",
              "components": "./components",
              "config": "./config",
              "lib": "./lib"
            }
          }
        ]
      ],
      "presets": [
        "react-native"
      ]
    }
  }
}

Maybe it helps somebody.

You have to change your presets to this

"presets": [
    "react-native-stage-0"
  ]

As per docs, though you install babel-preset-react-native-stage-0, your preset should be react-native-stage-0 or react-native-stage-0/decorator-support.

{
  "presets": ["react-native-stage-0"]
}

Do you want/need experimental legacy decorator support (provided by babel-plugin-transform-decorators-legacy)? Use this as your .babelrc instead:

{
  "presets": ["react-native-stage-0/decorator-support"]
}

Deleting .babelrc file will fix this for you.

Related