Export namespace should be first transformed by @babel/plugin-proposal-export-namespace-from

回答 3 浏览 1.4万 2022-07-10

当我想建立我的APK时,我得到了以下的错误。

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

enter image description here

不得不说我在index.js中导入了react-native-gesture-handler

这是我的 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);

在开发模式下,我没有得到这个错误。

这是我的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"
  }
}

我真的很感谢你能提供的任何帮助。

Aazam Heidari 提问于2022-07-10
请添加你的package.json。AbolfazlR 2022-07-10
3 个回答
#1楼 已采纳
得票数 52

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

打开你的项目根部的babel.config.js,并按以下方式进行修改。

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    ...
    'react-native-reanimated/plugin', // This line.
  ],
};

注意:react-native-reanimated/plugin添加到你的项目后,你可能会遇到一个假阳性的"Reanimated 2 failed to create a worklet" 错误。在大多数情况下,这可以通过清理应用程序的缓存来解决。根据你的工作流程或最喜欢的软件包管理器,可以通过以下方式完成:

yarn start --reset-cache
npm start -- --reset-cache
expo start -c

更多信息

AbolfazlR 提问于2022-07-10
AbolfazlR 修改于2022-07-13
#2楼
得票数 8

你的babel.config.js看起来应该是这样的

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: ['react-native-reanimated/plugin'],
};
Soumik Chakraborty 提问于2022-07-11
#3楼
得票数 0

你的babel.config.js可能看起来是这样的。

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ["babel-preset-expo"],
    plugins: [
      "react-native-reanimated/plugin", // This line.
    ],
  };
};

这对我来说是有效的。

questerstudios 提问于2022-10-10