How to use mobx in react-native 0.56 (Babel 7) with Decorators

后端 未结 2 1056
闹比i
闹比i 2020-12-24 15:08

i\'ve upgraded my RN app from 0.55.4 to 0.56 that use Babel 7.

In 0.55.4 to use decorators for MOBX i use \"babel-plugin-transform-decorators-legacy\" but is not com

相关标签:
2条回答
  • 2020-12-24 15:48

    I solved this issue by installing @babel/plugin-proposal-decorators@7.0.0-beta.47 and @babel/plugin-transform-runtime@7.0.0-beta.47.

    Versions might change for you. I used those versions because @babel/core was also at 7.0.0-beta.47.

    Current .babelrc is:

    {
      "presets": [
        "react-native"
      ],
      "plugins": [
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        ["@babel/plugin-transform-runtime", {
          "helpers": true,
          "polyfill": false,
          "regenerator": false
        }]
      ]
    }
    
    0 讨论(0)
  • 2020-12-24 15:59

    Ok, i solved all the errors by adding @babel/runtime, now the app works in DEBUG and RELEASE too.

    Here the correct configuration:

    package.json

    ...
    "devDependencies": {
      "@babel/core": "7.0.0-beta.47",
      "@babel/plugin-proposal-decorators": "7.0.0-beta.47",
      "@babel/plugin-transform-runtime": "7.0.0-beta.47",
      "@babel/runtime": "7.0.0-beta.47",
      "babel-jest": "23.2.0",
      "babel-preset-react-native": "5.0.2",
      "jest": "23.3.0",
      "react-test-renderer": "16.4.1"
    }
    ...
    

    .babelrc

    {
      "presets": [
        "react-native"
      ],
      "plugins": [
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        ["@babel/plugin-transform-runtime", {
          "helpers": true,
          "polyfill": false,
          "regenerator": false
        }]
      ]
    }
    

    Thanks @Hkan.

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