一直在从事一个通过create-react-native-app生成的项目.已经成功使用该项目一段时间了,但现在正试图通过exp start --tunnel测试该应用程序,我突然发现表单出现错误(尽管之前一直在工作):

[22:08:19] /path/to/node_modules/react-native-scripts/build/bin/crna-entry.js: Plugin/Preset files are not allowed to export objects, only functions. In /path/to/node_modules/babel-preset-expo/index.js
[22:08:19] Failed building JavaScript bundle.

我已经看到一些帖子似乎在处理这个问题(https://github.com/babel/babel/issues/6808Babel Plugin/Preset files are not allowed to export objects, only functions),但我对任何事情都没有react ,也没有完全理解bable是什么,所以我很难理解如何将这些帖子应用到我自己的情况.

我的bablerc文件(似乎与其他帖子相关)是:

{
  "presets": ["babel-preset-expo"],
  "env": {
    "development": {
      "plugins": ["transform-react-jsx-source"]
    }
  }
}

我试过npm cache clean --force && rm -rf node_modules && rm -f package-lock.json && npm install,但没有改变.What does seem to help is downgrading from react-native@0.56 to 0.55(正如这里所支持的:Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions),但这似乎并没有直接解决这个问题,更像是workaround.如果您对这里应该做什么有任何建议,我们将不胜感激(是否应该包括任何其他文件以帮助调试?).


**针对这个问题被标记为Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions的潜在副本,

  1. 这个问题实际上在帖子中被引用了,最后一段和最后一段解释了为什么尽管存在另一个问题,这个问题还是被贴了出来
  2. 我稍后对this个问题的回答向其他用户解释了why降级到0.55解决了问题(并引用了用户可以进一步判断的相关文档),在另一个引用的问题中(该问题的at the time条帖子)没有出现(尽管目前,将该问题标记为重复问题的用户现在在引用的问题中有一个答案,该答案也提到了0.55降级的原因).

推荐答案

发现问题在于:

在某个时刻,一定做了npm update次,将react native更新为0.56,expo更新为28.0.0.

查看react-native文档(https://facebook.github.io/react-native/docs/upgrading.html#create-react-native-app-projects),react-native似乎是require installing versions of 102, 103, and 104 that are all specifically compatible with each other.关于哪些版本的软件包彼此兼容的矩阵可以在这里找到:https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md

这些依赖项的每个版本仅与其他两个版本的一个狭窄版本范围兼容.

As of this writing该文件最后一次更新是在2018年4月27日,因此目前尚不清楚react和expo(最近发布了28.0.0版)的哪些版本应与现在的react结合使用-native@0.56.is记录的最新react-native 版本是react-native@0.55(配合react@16.3.1和expo@27.0.0),我想这就是为什么downgrading to react-native@0.55 was helpful in this case(我不知道为什么矩阵中没有react的文档)-native@0.56然而,我的Package.json现在看起来像:

...
"dependencies": {
    "@expo/vector-icons": "^6.3.1",
    "eslint": "^4.19.1",
    "expo": "^27.1.0",
    "prop-types": "^15.6.2",
    "react": "16.3.1",
    "react-native": "^0.55.4",
    "react-native-mail": "^3.0.6",
    "react-native-modal-dropdown": "^0.6.2",
    "react-navigation": "^2.6.2",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "tcomb-form-native": "^0.6.14",
    "uuid": "^3.3.2"
  }
}

React-native相关问答推荐

React Native在同一页面上使用多个不同的导航器

react native 如何更新倒置平面列表的数组中的项目

在 ReactNative 中调用 RCTDeviceEventEmitter.emit 时出错

为应用创建单个 MobX store 的最佳方式是什么?

React Native:双击退出应用程序

使用 resizeMode = contain时的图像对齐

用于 React-Native 开发的 Visual Studio Code 中的自动导入

自定义原生基础的选项卡

React Native Expo StackNavigator 重叠通知栏

如何将捕获的图像与 react-native-camera 一起使用

如何在 React Native 中使用 index.js 而不是 (index.ios.js, index.android.js) 进行跨平台应用程序?

expo 已过期卸载并再次运行以升级

React Native如何将this.setState更改传递给父级

React-Native 最低 Android API 级别

你好世界! React Native 程序在 Mac 上抛出Could not parse the simulator list output

React-native google 登录给开发人员错误

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

无法解析模块react-native-screen

如何在 React Native 中强制禁用 iOS 暗模式

React-Native 水平滚动视图分页:预览下一页/卡片