Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions

前端 未结 4 1273
抹茶落季
抹茶落季 2021-01-18 03:19

Need some help, I\'m getting a weird error out of left field that I have not been able to debug. This project was bundling successfully until yesterday after I setup my reac

相关标签:
4条回答
  • 2021-01-18 03:57

    My app is ejected and fagerbua's answer helped but I had to struggle a bit further to get it to work. I eventually started a fresh create-react-native-app, ejecting, and edited my package.json and .babelrc to use babel-preset-react-native, the 0.56.0 version of react-native, and the 16.4.1 version of react. I also had to remove the transform-react-jsx-source plugin from the .babelrc file. Below are the files used for a minimal working react-native@0.56.0 app:

    .babelrc file:

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

    package.json:

    {
      "name": "myapp",
      "version": "0.1.0",
      "private": true,
      "devDependencies": {
        "babel-preset-react-native": "^5",
        "jest": "^23.4.2",
        "jest-react-native": "^18.0.0",
        "react-test-renderer": "16.3.1"
      },
      "scripts": {
        "start": "react-native start",
        "android": "react-native run-android",
        "ios": "react-native run-ios",
        "test": "jest"
      },
      "jest": {
        "preset": "react-native"
      },
      "dependencies": {
        "react": "^16.4.1",
        "react-native": "^0.56.0"
      }
    }
    

    Once I got this working with the basic app, I copied these changes back into my main app, removed my node_modules folder, did npm install and everything just worked. I'm not sure if the updated jest version was needed, I don't use jest but it was automatically added on create.

    0 讨论(0)
  • 2021-01-18 04:11

    create-react-native-app uses Expo, which as of the current release (SDK v29) does not support React Native 0.56. Its release announcement explains why:

    We did not update to React Native 0.56.0 for this release for two reasons. First, and most notably, in React Native 0.56.0 babel was updated to 7.0.0-beta.47 from ^6.24.1. Previous experiences with babel updates have shown us that they can been frustrating and time consuming for developers who just want to ship their app and minimize the time spent on infrastructure thrashing, so we wanted to give this more time to stabilize.

    Second, 0.56.0 introduces some bugs and doesn’t include enough useful features and fixes over 0.55.4 to justify the tradeoff of updating babel.

    If you really want to use RN 0.56, and you don't need to use Expo, you can remove the dependency by running npm run eject in the project. You'll still get a similar error message when loading your app, but because of a different dependency that is introduced when you eject. To fix that, install babel-preset-react-native@5 and replace "babel-preset-react-native-stage-0/decorator-support" with "babel-preset-react-native" in the project's .babelrc file. (Note that .babelrc looks different after you've run the eject command.)

    0 讨论(0)
  • 2021-01-18 04:14

    I tried upgrading react-native from 0.55.2 to 0.53.0 and encountered this error. I didn't try tracking it down beyond that but downgrading react-native to 0.55 should fix it.

    0 讨论(0)
  • 2021-01-18 04:16

    As addition to @fagerbua answer. If you want to use react-native@0.56 you need to change .babelrc with { "presets": [ "react-native" ] } you don't need jest-react-native anymore, but you need to use babel-preset-react-native@5

    0 讨论(0)
提交回复
热议问题