简体   繁体   English

Babel错误:插件/预设文件不允许导出对象,仅可导出功能

[英]Babel Error: Plugin/Preset files are not allowed to export objects, only functions

I'm trying to run storybook on an expo installation. 我正在尝试在博览会安装上运行故事书。 So I only got expo and storybook in the app so far. 因此,到目前为止,我在该应用程序中仅拥有博览会和故事书。

I'm not able to start the storybook for web. 我无法启动网络故事书。

My package.json looks like this: 我的package.json看起来像这样:

"dependencies": {
  "expo": "^32.0.0",
  "react": "16.5.0",
  "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz"
},
"devDependencies": {
  "@babel/core": "^7.2.2",
  "@babel/preset-env": "^7.2.3",
  "@babel/preset-react": "^7.0.0",
  "@babel/runtime": "^7.2.0",
  "@storybook/addon-actions": "^4.1.6",
  "@storybook/addon-knobs": "^4.1.6",
  "@storybook/addon-links": "^4.1.6",
  "@storybook/addon-ondevice-knobs": "^4.1.6",
  "@storybook/addon-ondevice-notes": "^4.1.6",
  "@storybook/addons": "^4.1.6",
  "@storybook/react": "^4.1.6",
  "@storybook/react-native": "^4.1.6",
  "babel-loader": "^7",
  "babel-preset-expo": "^5.0.0",
  "prop-types": "^15.6.2",
  "react-dom": "16.5.0"
},

My babel.config.js looks like this; 我的babel.config.js看起来像这样;

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
  };
};

I have also tried with: 我也尝试过:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ["@babel/env", "@babel/react"],
  };
};

I get this error when trying to run the storybook: 尝试运行故事书时出现此错误:

ERROR in ./storybook/addons.js
Module build failed (from ./node_modules/@storybook/react-native/node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/kristoffernielsen/repos/app/storybook/node_modules/babel-preset-react/lib/index.js
    at createDescriptor (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
    at items.map (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
    at Array.map (<anonymous>)
    at createDescriptors (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at passPerPreset (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/config-descriptors.js:58:96)
    at cachedFunction (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/caching.js:33:19)
    at presets.presets (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/config-descriptors.js:29:84)
    at mergeChainOpts (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/config-chain.js:320:26)
    at /Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/config-chain.js:283:7
    at buildRootChain (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/config-chain.js:68:29)
    at loadPrivatePartialConfig (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/partial.js:85:55)
    at Object.loadPartialConfig (/Users/kristoffernielsen/repos/app/storybook/node_modules/@babel/core/lib/config/partial.js:110:18)
    at Object.<anonymous> (/Users/kristoffernielsen/repos/app/storybook/node_modules/@storybook/react-native/node_modules/babel-loader/lib/index.js:140:26)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/kristoffernielsen/repos/app/storybook/node_modules/@storybook/react-native/node_modules/babel-loader/lib/index.js:3:103)
 @ multi ./storybook/addons.js ./node_modules/@storybook/react-native/dist/manager/index.js manager[0]

It fails even though my addons.js is empty. 即使我的addons.js为空,它也会失败。

我已修复了此重命名删除或将文件重命名为rn-addons.js的问题。

That won't help you. 那对你没有帮助。 You still need your addon.js file. 您仍然需要addon.js文件。

Look here: https://github.com/storybooks/storybook/issues/5249 在这里看: https : //github.com/storybooks/storybook/issues/5249

I think you need to wait it out. 我认为您需要等待。

https://github.com/storybooks/storybook/issues/5249#issuecomment-472179512 https://github.com/storybooks/storybook/issues/5249#issuecomment-472179512

Just to add .babelrc to your storybook folder with the default react native or expo presets. 只需将.babelrc添加到默认反应本机或博览会预设的故事书文件夹中即可。

This works for me: 对我有用:

{
  "presets": ["module:metro-react-native-babel-preset"]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:插件/预设文件不允许导出对象,只能导出功能/ babel-preset-stage-0 - Error:Plugin /Preset files are not allowed to export objects,only functions/babel-preset-stage-0 Babel Plugin/Preset 文件不允许导出对象,只能导出函数 - Babel Plugin/Preset files are not allowed to export objects, only functions gulp-babel插件错误:不允许插件/预设文件导出对象,仅导出功能 - Error in plugin gulp-babel: Plugin/Preset files are not allowed to export objects, only functions Babel-Loader Error Plugin/Preset 文件不允许导出对象,只能导出函数 - Babel-Loader Error Plugin/Preset files are not allowed to export objects, only functions 出现“错误:插件/预设文件不允许导出对象,只能导出功能。” 来自 babel-preset-react-app/index.js - Getting "Error: Plugin/Preset files are not allowed to export objects, only functions." from babel-preset-react-app/index.js 反应错误:不允许插件/预设文件导出对象,仅导出功能 - error on react: Plugin/Preset files are not allowed to export objects, only functions 用graphql开玩笑,“插件/预设文件不允许导出对象,只能导出功能” - Jest with graphql, “Plugin/Preset files are not allowed to export objects, only functions” “ npm start”抛出错误:不允许插件/预设文件导出对象,仅导出功能 - “npm start” throws Error: Plugin/Preset files are not allowed to export objects, only functions 错误:插件/预设文件不允许导出对象,只能导出功能。 ReactJS - Error: Plugin/Preset files are not allowed to export objects, only functions. ReactJS 使用 JEST 和 Vue.js 失败“插件/预设文件不允许导出对象,只能导出函数。” - Fail with JEST and Vue.js "Plugin/Preset files are not allowed to export objects, only functions."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM