在 create-react-native-app 项目中突然看到错误 "Plugin/Preset files are not allowed to export objects, only functions"
Suddenly seeing error "Plugin/Preset files are not allowed to export objects, only functions" in create-react-native-app project
一直在处理通过 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.
已经看到一些似乎可以解决问题的 posts (https://github.com/babel/babel/issues/6808 and ),但是对于任何反应都是全新的并且没有完全理解 bable
是什么,所以我很难理解如何将这些 post 应用于我自己的情况。
我的 .bablerc 文件(因为它似乎与其他 posts 相关)是:
{
"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(如这里所提倡的:Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions),但这似乎并没有直接解决问题,更多的解决方法。任何有关此处应执行的操作的建议都将不胜感激(应包含任何其他文件以帮助调试?)。
** 回应这个问题被标记为 Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions 的潜在重复,
- 这个问题实际上在 post 中被引用了,并且在最后一段中包含了为什么 post 编辑了这个问题,尽管存在另一个问题
- 我后来对这个问题的回答向其他用户解释了为什么降级到 0.55 解决了问题(并引用了相关文档,用户可以进一步检查),其中(在这个问题 posting 的时间)没有出现在另一个引用的问题中(尽管目前,用户将这个问题标记为一个副本现在在引用的问题中有一个答案,该问题也讨论了为什么 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 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 并说
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.1 版本)。 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 现在看起来像:
...
"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 升级到了 0.56.0。
将 react-native 版本降级回 0.55.0 解决了我的问题
npm install react-native@0.55.0
原因已由@lampShadesDrifter 充分解释,但是我将添加一个更快的解决方案,即使用从 expo 捆绑的 react-native sdk:
https://github.com/expo/react-native/
因此,您可以将此添加到 expo sdk 29 的依赖项中:
"react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",
一直在处理通过 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.
已经看到一些似乎可以解决问题的 posts (https://github.com/babel/babel/issues/6808 and bable
是什么,所以我很难理解如何将这些 post 应用于我自己的情况。
我的 .bablerc 文件(因为它似乎与其他 posts 相关)是:
{
"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(如这里所提倡的:Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions),但这似乎并没有直接解决问题,更多的解决方法。任何有关此处应执行的操作的建议都将不胜感激(应包含任何其他文件以帮助调试?)。
** 回应这个问题被标记为 Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions 的潜在重复,
- 这个问题实际上在 post 中被引用了,并且在最后一段中包含了为什么 post 编辑了这个问题,尽管存在另一个问题
- 我后来对这个问题的回答向其他用户解释了为什么降级到 0.55 解决了问题(并引用了相关文档,用户可以进一步检查),其中(在这个问题 posting 的时间)没有出现在另一个引用的问题中(尽管目前,用户将这个问题标记为一个副本现在在引用的问题中有一个答案,该问题也讨论了为什么 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 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 并说
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.1 版本)。 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 现在看起来像:
...
"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 升级到了 0.56.0。 将 react-native 版本降级回 0.55.0 解决了我的问题
npm install react-native@0.55.0
原因已由@lampShadesDrifter 充分解释,但是我将添加一个更快的解决方案,即使用从 expo 捆绑的 react-native sdk: https://github.com/expo/react-native/
因此,您可以将此添加到 expo sdk 29 的依赖项中:
"react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",