突然看到错误“Plugin/Preset files are not allowed to export objects, only functions";在 create-react-native-app 项目中 [英] Suddenly seeing error "Plugin/Preset files are not allowed to export objects, only functions" in create-react-native-app project

查看:12
本文介绍了突然看到错误“Plugin/Preset files are not allowed to export objects, only functions";在 create-react-native-app 项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直致力于通过 create-react-native-app 生成的项目.已经成功使用该项目有一段时间了,但现在尝试通过 exp start --tunnel 测试该应用程序,我突然看到以下形式的错误(虽然以前可以工作):

Have been working on a project generated via create-react-native-app. Have been successfully using the project for some time, but now trying to test the app via exp start --tunnel, am suddenly seeing error (though was working previously) of the form:

[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 文件不允许导出对象,只能导出函数),但是对于 react-anything 来说是全新的,并且不完全了解 bable 是什么,所以我很难理解如何将这些帖子应用于我自己的情况.

Have seen some posts that seem to deal with the problem (https://github.com/babel/babel/issues/6808 and Babel Plugin/Preset files are not allowed to export objects, only functions), but am totally new to react-anything and don't fully get what bable is, so am having difficulty understanding how to apply these posts to my own situation.

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

My .bablerc file (as it seems to be relevant in the other posts) is:

{
  "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 没有变化.似乎有帮助的是从 react-native@0.56 降级到 0.55(如此处所提倡的:创建 React Native App. - 插件/预设文件不允许导出对象,只能导出函数),但这并不似乎直接解决了这个问题,更多的是解决方法.任何关于这里应该做什么的建议都将不胜感激(应该包含任何其他文件以帮助调试?).

Have tried npm cache clean --force && rm -rf node_modules && rm -f package-lock.json && npm install with no change. What does seem to help is downgrading from react-native@0.56 to 0.55 (as espoused here: Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions), but this does not seem to address the problem directly and more of a workaround. Any advice on what should be done here would be appreciated (any other files that should be included to help debug?).

** 回应这个问题被标记为 创建 React Native App.- 插件/预设文件不允许导出对象,只能导出函数,

** In response to this question being marked as a potential duplicate of Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions,

  1. 这个问题实际上是在帖子中引用的,并且在最后一段中包含了为什么尽管存在另一个问题而发布了这个问题的解释,并且
  2. 我稍后对 this 问题的回答向其他用户解释了为什么降级到 0.55 解决了问题(并引用了用户可以进一步检查的相关文档),其中(在发布此问题时)未出现在其他引用的问题中(尽管目前,已将此问题标记为重复的用户现在在引用的问题中有一个答案,该答案也谈到了原因0.55 降级有效).
  1. this question was actually cited in the post and explanation of why this question was posted despite the existence of the other was included in the last paragraph and
  2. my later answer to this question explains to other users why the downgrade to 0.55 resolves the problem (and cites relevant docs that users can further inspect), which (at the time of this question's posting) was not present in the other cited question (though presently, the user who has marked this question as a duplicate now has an answer in the cited question that does also talk about why the 0.55 downgrade works).

推荐答案

发现问题是这样的:

在某些时候,一定是做了一个 npm update 更新 react-native 到 0.56 和 expo 到 28.0.0.

At some point, must have done a npm update which updated react-native to 0.56 and expo to 28.0.0.

查看 react-native 文档(https://facebook.github.io/react-native/docs/upgrading.html#create-react-native-app-projects),react-native 似乎需要安装react-nativereactexpo 都特别相互兼容.可以在此处找到哪些软件包的哪些版本相互兼容的矩阵:https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md

Looking at the react-native docs (https://facebook.github.io/react-native/docs/upgrading.html#create-react-native-app-projects), react-native seems to require installing versions of react-native, react, and expo that are all specifically compatible with each other. A matrix of which versions of which packages are compatible with each other can be found here: https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md and says

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

Each version of these dependencies is only compatible with a narrow version range of the other two.

截至撰写本文时,该文档最后一次更新是在 2018 年 4 月 27 日,因此尚不清楚应该使用哪些版本的 react 和 expo(最近发布了 28.0.0 版)结合现在的 react-native@0.56. 记录的最新 react-native 版本是 react-native@0.55(与 react@16.3.1 和 expo@27.0.0 一起使用),我认为这就是为什么 降级到react-native@0.55 在这种情况下很有帮助(我不知道为什么矩阵中还没有 react-native@0.56 的文档),我的 package.json 现在看起来像:

As of this writing the document was last updated on April 27, 2018, so it is not exactly clear what versions of react and expo (which has recently released version 28.0.0) should be used in combination with the now-out react-native@0.56. The most recent react-native version that is documented is react-native@0.55 (to go with react@16.3.1 and expo@27.0.0), which I think is why downgrading to react-native@0.55 was helpful in this case (I don't know why there is no documentation in the matrix for react-native@0.56 yet), my package.json now looking like:

...
"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"
  }
}

这篇关于突然看到错误“Plugin/Preset files are not allowed to export objects, only functions";在 create-react-native-app 项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆