我已经将使用巴别塔7的RN应用程序从0.55.4升级到了0.56.

在0.55.4中,要使用MOBX的decorator ,我使用"babel plugin transform decorators legacy",但与babel 7不兼容...

react 本机版本:0.56.0

有人有解决办法吗?

谢谢

UPDATE:

该应用程序在DEBUG种配置下工作

package.json

...
"devDependencies": {
    "@babel/core": "7.0.0-beta.47",
    "@babel/plugin-proposal-decorators": "7.0.0-beta.47"
    ...
}

.babelrc

{
  "presets": [
    ["react-native"]
  ],
  "plugins": [
    ["@babel/plugin-proposal-decorators", { "legacy": true }]
  ]
}

但在RELEASE xCode崩溃时,出现了以下错误:

babelHelpers.applyDecoratedDescriptor is not a function.

UPDATE 2, WORKING CONFIG:

这是我的工作配置:

package.json

...
"devDependencies": {
   "@babel/core": "7.0.0-beta.47",
   "@babel/plugin-proposal-decorators": "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 }]
  ]
}

然后在索引中.js(主应用程序启动文件)我需要导入decorators babel库:

index.js

import applyDecoratedDescriptor from '@babel/runtime/helpers/es6/applyDecoratedDescriptor';
import initializerDefineProperty from '@babel/runtime/helpers/es6/initializerDefineProperty';

Object.assign(babelHelpers, {applyDecoratedDescriptor, initializerDefineProperty});

require('./app.js');

app.js

import {AppRegistry} from 'react-native';
import AppName from './app/index';

AppRegistry.registerComponent(appName, () => AppName);

推荐答案

好的,我通过添加@babel/runtime解决了所有错误,现在应用程序也可以在DEBUGRELEASE中工作.

以下是正确的配置:

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

谢谢@Hkan.

React-native相关问答推荐

使用NextJS映射从数组中提取用户角色

Firebase身份验证Redux使用说明

单击时更改ToucheableOpacity colored颜色 不起作用

expo 日历应用因权限问题而崩溃

GetStream:更改消息气泡背景

如何将 react-native 图像从 expo-image-picker 上传到使用 multer 的 Express.js 后端

新的 react-native ios 应用程序没有构建?

React Native 的 Firebase 初始错误(无法读取未定义的属性getItem)

React Native WebView onMessage 没有做任何事情

我如何知道我的代码是否作为 React Native 运行

React Native 入门元素Bundle 失败,出现 Unexpected Token 错误

如何在 mac 上卸载 react-native-cli?

Undefined 不是判断 this.state.* 的对象

如何从 React Native 应用程序打开 Google Play store ?

在 React-Native 中手动设置 opacity 的 onPress of TouchableOpacity 的音量

React Native 将状态中的数组值应用为 Picker 项

我将如何根据百分比为按钮的宽度设置动画,并且它的背景 colored颜色 也是如此?

Expo LAN 配置不适用于新的 ReactNative 元素

React Native:如何将文件拆分为多个文件并导入它们?

Gradlew bundleRelease 不会在 react-native 中生成发布 apk