[英]Storybook in Create-react-app: typeError: args.flat is not a function
I have installed storybook in a create-react app
application thanks to the command npx -p @storybook/cli sb init
.由于命令
npx -p @storybook/cli sb init
,我已经在create-react app
程序应用程序中安装了故事书。 Then, I added a basic story to the stories folder.然后,我在故事文件夹中添加了一个基本故事。 When launching storybook, it crashes and says:
typeError: args.flat is not a function
启动故事书时,它崩溃并说:
typeError: args.flat is not a function
Here is my story:这是我的故事:
import React from "react"; import Hello from "./components/Hello"; import faker from "faker"; const text = faker.internet.email(); export const Default = () => { return <Hello text={text} />; };
And the config:和配置:
module.exports = { stories: ['../src/**/*.stories.js'], addons: [ '@storybook/preset-create-react-app', '@storybook/addon-actions', '@storybook/addon-links', ], };
I tried to replace it with a custom config:我试图用自定义配置替换它:
import { configure } from "@storybook/react"; function loadStories() { const req = require.context("../src/stories", true, /\.stories\.js$/); req.keys().forEach((filename) => req(filename)); } configure(loadStories, module);
How to fix this?如何解决这个问题?
Upgrade your node version, any version above 12 must work.升级你的节点版本,任何高于 12 的版本都必须工作。
If you are using nvm如果您使用的是 nvm
nvm install --lts
There is an issue with below command that is supposed to automatically detect underlying framework.以下命令存在问题,应该自动检测底层框架。 Launching storybook fails with
args.flat is not a function
error启动故事书失败,
args.flat is not a function
错误
npx -p @storybook/cli sb init
Use this instead改用这个
npx -p @storybook/cli sb init --type react
If you already have storybook pre-installed and face this error, overwrite it with -f command如果您已经预装了故事书并遇到此错误,请使用 -f 命令覆盖它
npx -p @storybook/cli sb init --type react -f
I have experienced the same problem today and fixed it by installing Storybook v. 5.3.19
through Manual setup .我今天遇到了同样的问题,并通过Manual setup安装
Storybook v. 5.3.19
来修复它。 Looks like there are some compatibility problems between create-react-app
and Storybook 6.+ beta-versions.看起来
create-react-app
和 Storybook 6.+ beta 版本之间存在一些兼容性问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.