问题
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
- uninstalling latest version of babel-preset-react-native and re-installing sudo yarn add babel-preset-react-native@2.1.0
- Clear cache Yarn Cache, npm cache
- deleting build folder, deleting npm modules and reinstall all modules
- Few people fixed the issue by removing watchman, but I am not using watchman at all.
- 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:
- $
cd your_project
- $
nano .babelrc
(Or any editor that you wants) - Copy and paste #A
If you didn't have .babelrc in your project, then:
$ cd your_project
touch .babelrc
- 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