简体   繁体   English

Webpack 错误将故事书添加到 create-react-app

[英]Webpack error adding storybook to create-react-app

Today I created a new CRA project (working perfectly) but when I add Storybook with npx sb init I get this error:今天我创建了一个新的 CRA 项目(运行良好),但是当我使用npx sb init添加 Storybook 时,我收到了这个错误:

 info @storybook/react v6.4.9 info => Loading presets info => Serving static files from./public at / info => Loading Webpack configuration from `node_modules/react-scripts` info => Removing existing JavaScript and TypeScript rules. info => Modifying Create React App rules. info => Using default Webpack5 setup ERR: ValidationError. Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema. ERR. - configuration:module.rules[4] should be one of these. ERR. ["?,?" | object { assert,? compiler,? dependency,? descriptionData,? enforce,? exclude,? generator,? include,? issuer,? issuerLayer,? layer,? loader,? mimetype,? oneOf,? options,? parser,? realResource,? resolve,? resource,? resourceFragment,? resourceQuery,? rules,? scheme,? sideEffects,? test,? type,. use. }. ...]

I tried a lot of things with no results.我尝试了很多东西都没有结果。

What could it be?会是什么呢?

Thank you!谢谢!

Webpack has been initialized using a configuration object that does not match the API schema. Webpack 已使用与 API 模式不匹配的配置 object 进行了初始化。

Please review your webpack configuration: https://storybook.js.org/docs/react/configure/webpack请查看您的 webpack 配置: https://storybook.js.org/docs/react/configure/webpack

Storybook 6.3 brings opt-in support for building both your project and the manager UI with webpack 5. To do so: Storybook 6.3 为使用 webpack 5 构建您的项目和管理器 UI 提供了可选支持。为此:

yarn add @storybook/builder-webpack5 @storybook/manager-webpack5 --dev

# or

npm install @storybook/builder-webpack5 @storybook/manager-webpack5 --save-dev

Then edit your.storybook/main.js config:然后编辑 your.storybook/main.js 配置:

module.exports = {
  core: {
    builder: 'webpack5',
  },
};

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM