导出命名空间应首先通过 `@babel/plugin-proposal-export-namespace-from` 进行转换

Aaz*_*ari 32 react-native react-navigation

当我想要构建我的 APK 时,出现以下错误。

导出命名空间应首先转换为 @babel/plugin-proposal-export-namespace-from

在此输入图像描述

我需要说我已经导入react-native-gesture-handler了index.js

这是我的index.js

import 'react-native-gesture-handler';
import {AppRegistry} from 'react-native';
import App from './app/App';
import {name as appName} from './app.json';

import { LogBox } from 'react-native';
LogBox.ignoreAllLogs();


AppRegistry.registerComponent(appName, () => App);
Run Code Online (Sandbox Code Playgroud)

在开发模式下,我没有收到该错误。

这是我的 package.json

{
  "name": "blackout",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.17.6",
    "@react-native-community/geolocation": "^2.1.0",
    "@react-native-community/netinfo": "^9.0.0",
    "@react-native-community/viewpager": "^5.0.11",
    "@react-navigation/bottom-tabs": "^6.3.1",
    "@react-navigation/native": "^6.0.10",
    "@react-navigation/native-stack": "^6.6.2",
    "@react-navigation/stack": "^6.2.1",
    "axios": "^0.27.2",
    "es6-template-strings": "^2.0.1",
    "jalali-moment": "^3.3.11",
    "jwt-decode": "^3.1.2",
    "react": "17.0.2",
    "react-hook-form": "^7.32.2",
    "react-native": "0.68.2",
    "react-native-android-open-settings": "^1.3.0",
    "react-native-audio-recorder-player": "^3.5.1",
    "react-native-device-info": "^9.0.2",
    "react-native-element-dropdown": "^2.0.0",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^2.4.2",
    "react-native-image-crop-picker": "^0.37.3",
    "react-native-image-picker": "^4.8.4",
    "react-native-modal": "^13.0.1",
    "react-native-reanimated": "^2.9.1",
    "react-native-safe-area-context": "^4.3.1",
    "react-native-screens": "^3.13.1",
    "react-native-size-matters": "^0.4.0",
    "react-native-snackbar": "^2.4.0",
    "react-native-tab-view": "^3.1.1",
    "react-native-vector-icons": "^9.1.0",
    "react-native-video": "^5.2.0",
    "react-native-webview": "^11.22.2",
    "react-redux": "^8.0.2",
    "realm": "10.19.5",
    "redux": "^4.2.0",
    "redux-thunk": "^2.4.1",
    "rn-fetch-blob": "^0.12.0"
  },
  "devDependencies": {
    "@babel/code-frame": "^7.16.7",
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.67.0",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}
Run Code Online (Sandbox Code Playgroud)

我非常感谢您提供的任何帮助。

Abo*_*zlR 71

您必须将其添加'react-native-reanimated/plugin'插件数组中。确保这个插件应该是最后一个

打开项目根目录下的babel.config.js并修改如下:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    ...
    'react-native-reanimated/plugin', // This line.
  ],
};
Run Code Online (Sandbox Code Playgroud)

注意:添加到react-native-reanimated/plugin项目后,您可能会遇到误报“Reanimated 2 无法创建工作集”错误。在大多数情况下,可以通过清理应用程序的缓存来解决此问题。根据您的工作流程或最喜欢的包管理器,可以通过以下方式完成:

yarn start --reset-cache
npm start -- --reset-cache
expo start -c
Run Code Online (Sandbox Code Playgroud)

了解更多信息


Sou*_*rty 11

你的 babel.config.js 应该看起来像

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: ['react-native-reanimated/plugin'],
};
Run Code Online (Sandbox Code Playgroud)


Tre*_*red 5

React-native-reanimated 2.9 和 2.12 之间似乎发生了重大变化。最新版本不再引用@babel/plugin-proposal-export-namespace-from。为了解决这个问题,我遵循了在此提交中找到的示例。

将其添加到 babel.config.js 中:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    ...
    'react-native-reanimated/plugin',
    '@babel/plugin-proposal-export-namespace-from',
  ],
};
Run Code Online (Sandbox Code Playgroud)

然后运行这些命令:

yarn add @babel/plugin-proposal-export-namespace-from
yarn start -c
Run Code Online (Sandbox Code Playgroud)