react native transform - error couldn't find p

2019-06-28 01:39发布

问题:

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"]
    }
  }
}