创建React Native App -不允许插件/预设文件导出对象,仅导出功能 [英] Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions

查看:165
本文介绍了创建React Native App -不允许插件/预设文件导出对象,仅导出功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要一些帮助,我从左侧字段中收到一个奇怪的错误,我无法调试.在另一台Mac上设置我的react native项目后,该项目一直成功捆绑到昨天.

Need some help, I'm getting a weird error out of left field that I have not been able to debug. This project was bundling successfully until yesterday after I setup my react native project on another Mac.

我想知道它是否来自必须重新安装的npm软件包的版本控制.

I'm wondering if it's from versioning of npm packages I had to reinstall.

任何方向都是有帮助的,因为最难的是设置,因为您很少这样做...

Any direction would be helpful, it's always the setup that's the hardest because you do it so infrequently...

我的babelrc文件如下-

My babelrc file is as follows --

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

还有我的package.json

And my package.json

{
  "name": "hancho_frontend",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "jest-expo": "~27.0.0",
    "react-native-scripts": "^1.14.1",
    "react-test-renderer": "16.3.1"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "jest"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^6.2.0",
    "axios": "^0.18.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-upgrade": "0.0.19",
    "color": "^2.0.0",
    "expo": "^27.1.0",
    "hoist-non-react-statics": "^2.3.0",
    "moment": "^2.22.2",
    "prop-types": "^15.6.2",
    "react": "^16.3.1",
    "react-dom": "^16.4.1",
    "react-fontawesome": "^1.6.1",
    "react-native": "^0.56.0",
    "react-native-dropdownalert": "^3.1.2",
    "react-native-extended-stylesheet": "^0.8.0",
    "react-navigation": "^2.6.1",
    "react-redux": "^5.0.7",
    "react-router-dom": "^4.3.1",
    "redux": "^4.0.0",
    "redux-axios-middleware": "^4.0.0",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0",
    "webpack": "^4.15.1"
  }
}

我肯定已经安装了不使用的软件包,但是过去并没有引起问题.

I definitely have packages I am not using installed, but it has not caused a problem in the past.

我已清除缓存,已卸载并重新安装了node_modules.我还恢复了以前工作过的EXPO的早期版本.仍然没有运气.

I've cleared cache, uninstalled and reinstalled node_modules. I also reverted to an earlier version of expo that I had working previously. Still no luck.

提前谢谢!

推荐答案

create-react-native-app使用Expo,它在当前版本(SDK v29)中不支持React Native 0.56.其发行公告解释了原因:

create-react-native-app uses Expo, which as of the current release (SDK v29) does not support React Native 0.56. Its release announcement explains why:

由于以下两个原因,我们没有将此版本更新为React Native 0.56.0.首先,也是最值得注意的是,在React Native 0.56.0中,babel从^ 6.24.1更新为7.0.0-beta.47.以前使用babel更新的经验向我们表明,对于只想发布其应用程序并最大程度减少基础架构颠簸时间的开发人员来说,它们可能令人沮丧且耗时,因此我们希望给此更多的时间来稳定它们.

We did not update to React Native 0.56.0 for this release for two reasons. First, and most notably, in React Native 0.56.0 babel was updated to 7.0.0-beta.47 from ^6.24.1. Previous experiences with babel updates have shown us that they can been frustrating and time consuming for developers who just want to ship their app and minimize the time spent on infrastructure thrashing, so we wanted to give this more time to stabilize.

第二,0.56.0引入了一些错误,并且没有包含足够的有用功能,并且修复了0.55.4以上的问题,以证明需要更新babel.

Second, 0.56.0 introduces some bugs and doesn’t include enough useful features and fixes over 0.55.4 to justify the tradeoff of updating babel.

如果您确实要使用RN 0.56,并且不需要使用Expo,则可以通过在项目中运行npm run eject来删除依赖项.加载应用程序时,您仍然会收到类似的错误消息,但是由于弹出时引入了不同的依赖关系.要解决此问题,请安装babel-preset-react-native@5并替换为"babel-preset-react-native-stage-0/decorator-support".带有巴比尔预置反应本机".在项目的.babelrc文件中. (请注意,运行弹出命令后,.babelrc看起来会有所不同.)

If you really want to use RN 0.56, and you don't need to use Expo, you can remove the dependency by running npm run eject in the project. You'll still get a similar error message when loading your app, but because of a different dependency that is introduced when you eject. To fix that, install babel-preset-react-native@5 and replace "babel-preset-react-native-stage-0/decorator-support" with "babel-preset-react-native" in the project's .babelrc file. (Note that .babelrc looks different after you've run the eject command.)

这篇关于创建React Native App -不允许插件/预设文件导出对象,仅导出功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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