插件/预设文件不允许导出对象,只有功能
Posted
技术标签:
【中文标题】插件/预设文件不允许导出对象,只有功能【英文标题】:Plugin/Preset files are not allowed to export objects, only functions 【发布时间】:2018-12-19 03:47:15 【问题描述】:将 react-native 更新为 "^0.56.0"
后出现此错误:
bundling failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/ben/vepo/frontend/node_modules/babel-preset-flow/lib/index.js
我尝试做一些类似于此处投票最高的答案,但改为使用 babel-preset-flow:
https://github.com/babel/babel-loader/issues/540
.babelrc:
"presets": ["react-native", "flow", "@babel/preset-flow"]
package.json
"name": "vepo",
"version": "0.0.1",
"private": true,
"scripts":
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
,
"rnpm":
"assets": [
"./app/fonts"
]
,
"jest":
"preset": "react-native",
"moduleNameMapper":
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
,
"dependencies":
"@babel/preset-flow": "^7.0.0-beta.52",
"@babel/preset-react": "^7.0.0-beta.52",
"babel-preset-react-native": "^4.0.0",
"flow-typed": "^2.4.0",
"generator-rn-toolbox": "^2.2.0",
"imagemagick": "^0.1.3",
"immutable": "4.0.0-rc.9",
"metro-bundler": "^0.22.1",
"native-base": "^2.3.3",
"prop-types": "^15.5.10",
"react": "16.3.1",
"react-native": "^0.56.0",
"react-native-aws3": "^0.0.8",
"react-native-blur": "^3.1.3",
"react-native-communications": "^2.2.1",
"react-native-drawer": "^2.3.0",
"react-native-fbsdk": "facebook/react-native-fbsdk#065507a",
"react-native-git-upgrade": "^0.2.7",
"react-native-image-picker": "^0.26.7",
"react-native-interactable": "^0.1.2",
"react-native-mail": "^3.0.2",
"react-native-maps": "^0.16.4",
"react-native-modal": "^2.3.2",
"react-native-modalbox": "^1.3.9",
"react-native-multiple-choice": "^0.0.8",
"react-native-navigation": "^1.1.100",
"react-native-off-canvas-menu": "^0.1.31",
"react-native-optimized-flatlist": "^1.0.1",
"react-native-redux-router": "^1.0.7",
"react-native-select-multiple": "^1.0.3",
"react-native-side-menu": "^0.20.1",
"react-native-vector-icons": "^4.4.0",
"react-navigation": "^1.0.0-beta.11",
"react-redux": "^5.0.3",
"redux": "^3.6.0",
"redux-immutable": "^4.0.0",
"redux-observable": "^0.14.1",
"reselect": "^3.0.0",
"rxjs": "^5.2.0",
"yarn": "^1.3.2",
"yoga": "^0.0.0"
,
"devDependencies":
"adm-zip": "^0.4.7",
"babel-cli": "^6.26.0",
"babel-eslint": "^7.1.1",
"babel-plugin-module-resolver": "^2.7.0",
"eslint": "^3.17.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-flowtype": "^2.30.3",
"eslint-plugin-jsx": "^0.0.2",
"eslint-plugin-react": "^6.10.0",
"eslint-plugin-react-native": "^2.3.1",
"flow-bin": "^0.72.0",
"plist": "^2.1.0",
"react-devtools": "^3.2.1",
"react-test-renderer": "~15.4.1",
"redux-devtools": "^3.3.2",
"remote-redux-devtools": "^0.5.7",
"remotedev-server": "^0.2.4",
"xcode": "^1.0.0"
没有任何工作。有什么想法吗?
编辑:根本没有 node_modules/babel-preset-flow 文件夹
【问题讨论】:
你能解决这个问题吗?,我有同样的错误:( @Guille 不,我无法修复这个错误,所以我恢复到 react-native 版本 0.55.4,它对我来说没有错误。 【参考方案1】:我遇到了同样的错误并通过卸载babel-preset-flow
并安装@babel/preset-flow
解决了它。我相信这是由于 React Native 56 使用 Babel 7。并添加到 .babelrc
"presets": ["@babel/preset-flow"]
【讨论】:
感谢这也解决了我的问题,为节省我的时间点赞! 谢谢这也解决了我的问题。尝试关注此文档flow.org/en/docs/react 我收到 == 错误:无法从升级你的 babel-preset-react-native 依赖。
"babel-preset-react-native": "^5",
您无需安装@babel/preset-react
或@babel/preset-flow
。
希望这会有所帮助。
【讨论】:
没有解决我的问题:s 我正在使用排毒,但仍然遇到同样的错误并做出反应0.55.4
【参考方案3】:
打开.babelrc
文件,然后编辑代码的presets部分如下:
"presets": ["module:metro-react-native-babel-preset"],
【讨论】:
在此之后,我遇到了另一个问题,在那里解决了 ***.com/questions/51765313/… ,然后它开始工作了【参考方案4】:我通过在我的项目中安装"babel-preset-react-native-stage-0"
解决了这个问题并更改了.babelrc
文件:
"presets": [
"babel-preset-react-native-stage-0/decorator-support"
]
【讨论】:
【参考方案5】:对于 Babel 7 及更高版本,根据 this document 创建一个名为 bable.config.js
而不是 .babelrc
的文件,然后像这样导出预设:
const presets = [
"flow"
]
module.exports = presets
【讨论】:
以上是关于插件/预设文件不允许导出对象,只有功能的主要内容,如果未能解决你的问题,请参考以下文章