Error in postcss/css loader with create-react-app @storybook/react v5.2.6
See original GitHub issueDescribe the bug When using a standard/new project created with create-react-app 3.2.0 and Storybook 5.2.6, Storybook fails to build any React component with which imports a CSS file with the following:
ERROR in ./src/HeaderLogo.css (./node_modules/css-loader/dist/cjs.js??ref--7-oneOf-3-1!./node_modules/postcss-loader/src??postcss!./node_modules/@storybook/core/node_modules/style-loader!./node_modules/@storybook/core/node_modules/css-loader/dist/cjs.js??ref--9-1!./node_modules/postcss-loader/src??postcss!./src/HeaderLogo.css)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
SyntaxError
(2:1) Unknown word
To Reproduce Steps to reproduce the behavior:
- Create a new application using create-react-app (latest was 3.2.0 when last created) and typescript configuration (I’m assuming typescript does not cause this problem)
- Add Storybook
npx -p @storybook/cli sb init
- Add a very simple story that uses a component that does an import of a CSS file:
import './MyComponent.css'
- Build will fail
Expected behavior Build will not fail
Build Output
info @storybook/react v5.2.6
info
info => Loading static files from: /Users/mattmassey/work/storydemo/public .
info => Loading presets
info => Loading presets
info => Loading custom addons config.
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 Webpack setup.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Errors thrown when integrating Storybook with Webpack 5 ...
I am getting 2 errors and haven't been able to resolve them: 1) complaining that I am missing an appropriate loader to handle...
Read more >Storybook Addon PostCSS
Storybook addon used to run the PostCSS preprocessor against your stories.
Read more >Setting up Storybook with Material UI and Styled Components
Recently I started experimenting with Material UI, a project that provides a set of React components that follow Google's Material Design ...
Read more >storybook/preset-create-react-app - npm
One-line Create React App configuration for Storybook. This preset is designed to use alongside @storybook/react .
Read more >Add PostCSS to Create-React-App - DEV Community
In the end, after a bit of trial and error hacking together different solutions, I got it working. Here's how! You can find...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The reason for this is because there is a problem with the Storybook integration with the CRA build scripts. Its inserting two CSS loader rules which are conflicting with each other. The solution is to remove one of the rules, since they are basically the same in the webpack config. A temporary work-around is to add a custom
webpack.config.js
in the.storybook
folder that has the following:@shilman Confirmed that 1.3.2 fixes this issue. Thanks for the quick work