react native transform - error couldn't find preset "babel-preset-react-native-stage-0

纵然是瞬间 提交于 2019-12-10 15:29:25

问题


I started ejecting expo, after so much struggle I could able to solve all build issues. When I run the app using 'sudo react-native run-android' I started getting following error

Error:

The development server returned response code 500
Bundling `index.android.js`  [development, non-minified, hmr disabled]  
0.0% (0/1), failed.
error: bundling failed: "TransformError: 

/Development/SourceCode/MobileApp/index.android.js: 
Couldn't find preset \"babel-preset-react-native-stage-0/decorator-support\" relative to directory \"/Development/SourceCode/MobileApp\""

I tried almost all possible fixes given in github and SO

  1. uninstalling latest version of babel-preset-react-native and re-installing sudo yarn add babel-preset-react-native@2.1.0
  2. Clear cache Yarn Cache, npm cache
  3. deleting build folder, deleting npm modules and reinstall all modules
  4. Few people fixed the issue by removing watchman, but I am not using watchman at all.
  5. Adding .babelrc mentioning decorator-support for preset as follows, this fix also didn't work.

.babelrc file looks like this

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

None of those fixes worked for me. using babel-preset-react-native@2.1.0 also didn't fix the issue because that was the major fix.


回答1:


Try to use normal babel preset 0 as per: https://babeljs.io/docs/plugins/preset-stage-0

so

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



回答2:


You can create .babelrc file in root of you project with following content if you cany use old version of React Native:

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



回答3:


If you did use Expo in your project,

try:

  1. $ cd your_project
  2. $ nano .babelrc (Or any editor that you wants)
  3. Copy and paste #A

If you didn't have .babelrc in your project, then:

  1. $ cd your_project
  2. touch .babelrc
  3. copy and paste #A

#A

{
  "presets": ["babel-preset-expo"],
  "env": {
    "development": {
      "plugins": ["transform-react-jsx-source"]
    }
  }
}


来源:https://stackoverflow.com/questions/50125294/react-native-transform-error-couldnt-find-preset-babel-preset-react-native-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!