首页 > 解决方案 > React Native:插件/预设文件不允许导出对象,只能导出函数

问题描述

我是 react-native 的新手,我正在尝试使用 mobx 建立一个项目(使用装饰器),但是在使用 expo start 命令时出现以下错误(我正在使用 expo)。

这是我的完整错误信息:

Failed building JavaScript bundle.
App.js: Plugin/Preset files are not allowed to export objects, only functions. In C:\xampp\htdocs\second-try\node_modules\babel-preset-react-native\index.js
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, lstat 'C:\xampp\htdocs\second-try\node_modules\.staging\@babel'
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.<anonymous> (C:\xampp\htdocs\second-try\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqCallback.oncomplete (fs.js:167:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'lstat',
  path: 'C:\\xampp\\htdocs\\second-try\\node_modules\\.staging\\@babel'
}

这是我的 babel 配置文件:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo', "react-native", "react-native-stage-0/decorator-support"],
  };
};

还有我的 package.json 文件:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/native": "^5.7.0",
    "@react-navigation/stack": "^5.7.0",
    "axios": "^0.19.2",
    "babel-preset-react-native-stage-0": "^1.0.1",
    "expo": "~38.0.8",
    "expo-status-bar": "^1.0.2",
    "install": "^0.13.0",
    "mobx": "^5.15.4",
    "react": "~16.11.0",
    "react-dom": "~16.11.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-reanimated": "^1.9.0",
    "react-native-safe-area-context": "^3.0.7",
    "react-native-screens": "^2.9.0",
    "react-native-web": "~0.11.7",
    "react-navigation": "^4.4.0"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "babel-preset-expo": "~8.1.0"
  },
  "private": true
}

标签: reactjsreact-native

解决方案


推荐阅读