storybook: Storybook doesn't work with the newest version 10.0.1 of PostCSS Autoprefixer plugin
Describe the bug
Storybook is failing to build itself when using newest versions of autoprefixer, postcss and postcss-loader
To Reproduce Steps to reproduce the behavior:
- Install newest versions of
autoprefixer(10.0.1),postcss(8.1.1) andpostcss-loader(4.0.3) - Use custom webpack configuration (which includes
postcss-loader) - Run a command to build storybook
- See the build fail with an error:
info => Building preview..
info => Loading preview config..
info => Loading presets
info => Loading config/preview file in ".storybook".
info => Loading config/preview file in ".storybook".
info => Adding stories defined in ".storybook/main.js".
info => Using custom .postcssrc.js
info => Loading custom Webpack config (full-control mode).
info => Compiling preview..
ERR! => Failed to build the preview
ERR! ./node_modules/@mdi/font/css/materialdesignicons.css (./node_modules/css-loader/dist/cjs.js??ref--5-1!./node_modules/@storybook/core/node_modules/postcss-loader/src??ref--5-2!./node_modules/@mdi/font/css/materialdesignicons.css)
ERR! Module build failed (from ./node_modules/@storybook/core/node_modules/postcss-loader/src/index.js):
ERR! Error: PostCSS plugin autoprefixer requires PostCSS 8.
ERR! Migration guide for end-users:
ERR! https://github.com/postcss/postcss/wiki/PostCSS-8-for-end-users
ERR! at Processor.normalize (/Users/<project-path>/node_modules/@storybook/core/node_modules/postcss/lib/processor.js:153:15)
ERR! at new Processor (/Users/<project-path>/node_modules/@storybook/core/node_modules/postcss/lib/processor.js:56:25)
ERR! at postcss (/Users/<project-path>/node_modules/@storybook/core/node_modules/postcss/lib/postcss.js:55:10)
ERR! at /Users/<project-path>/node_modules/@storybook/core/node_modules/postcss-loader/src/index.js:140:12
ERR! @ ./node_modules/@mdi/font/css/materialdesignicons.css 2:26-182
ERR! @ ./src/plugins/vuetify.js
ERR! @ ./.storybook/preview.js
ERR! @ ./.storybook/preview.js-generated-config-entry.js
ERR! @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/storybook-init-framework-entry.js ./node_modules/@storybook/addon-knobs/dist/preset/addDecorator.js-generated-other-entry.js ./node_modules/@storybook/addon-actions/dist/preset/addDecorator.js-generated-other-entry.js ./node_modules/@storybook/addon-actions/dist/preset/addArgs.js-generated-other-entry.js ./.storybook/preview.js-generated-config-entry.js ./.storybook/generated-stories-entry.js
(node:81728) UnhandledPromiseRejectionWarning: [object Object]
(node:81728) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 703)
(node:81728) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
System
Please paste the results of npx sb@next info here.
Environment Info:
System:
OS: macOS 10.15.7
CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
Binaries:
Node: 12.11.1 - ~/.nvm/versions/node/v12.11.1/bin/node
Yarn: 1.22.10 - ~/<project-path>/node_modules/.bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v12.11.1/bin/npm
Browsers:
Chrome: 85.0.4183.121
Firefox: 81.0
Safari: 14.0
npmPackages:
@storybook/addon-actions: ^6.0.26 => 6.0.26
@storybook/addon-knobs: ^6.0.26 => 6.0.26
@storybook/addons: ^6.0.26 => 6.0.26
@storybook/vue: ^6.0.26 => 6.0.26
Additional context
It looks like the problem comes from the fact that Storybook uses it’s own version of postcss-loader, which comes with it’s own version 7.x of postcss
One solution that I see is to update postcss-loader and postcss
Another - provide a way to use project’s versions of postcss-loader and postcss dependencies
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 59
- Comments: 54 (15 by maintainers)
Commits related to this issue
- Use postcss@^7 to fix sb build issues, use compat tailwind versions - https://tailwindcss.com/docs/installation#post-css-7-compatibility-build - https://github.com/storybookjs/storybook/issues/12668 — committed to ndrsllwngr/omm by ndrsllwngr 4 years ago
- Fix storybook build There is an incompatibility between storybook and the latest version of postcss (see: storybookjs/storybook#12668) which we didn't notice because we weren't generating the actual ... — committed to mozilla/glean-dictionary by wlach 4 years ago
- Fix storybook generation and build storybook in CI (#245) There is an incompatibility between storybook and the latest version of postcss (see: storybookjs/storybook#12668) which we didn't notice b... — committed to mozilla/glean-dictionary by wlach 4 years ago
I also get the same issue as @matamatanot (also with tailwind 2.0.2)
I might have missed something from my config after doing
It’s really not very clear what needs to be changed (if anything) to this to get storybook working with postcss 8 other than running the above command
Any guidance would be great but right now there’s no difference than running the current version of sb, with my app running normally on postcss 8, but storybook failing.
Edit:
Looks like
@storybook/addon-postcssdoes NOT get added automatically with the alpha version of storybook, but is required to fix the postcss errors.Solution:
your package.json should now look like this
your package.json should now look like this
Hi @developer-rakeshpaul,
At the end I followed the instructions at https://tailwindcss.com/docs/installation#post-css-7-compatibility-build and everything works like a charm without dirty hacks.
I created a sample project: https://github.com/4lejandrito/storybook-tailwind2.
Crikey!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.2.0-alpha.15 containing PR #13640 that references this issue. Upgrade today to the
@nextNPM tag to try it out!Closing this issue. Please re-open if you think there’s still more to do.
Got running in 6.2.9 with https://github.com/storybookjs/storybook/issues/12668#issuecomment-773958085 , but after upgrading to 6.3.0 error is back.
It seems like a lot of workarounds depend on Tailwind, but for anyone who ends up here in despair, this is unrelated to Tailwind, so it may happen to you (as it does to us) even if you’re not using Tailwind.
In our case, we’re using plain PostCSS with Autoprefixer, postcss-url, etc. @shilman, are there any plans to upgrade the version of PostCSS that Storybook uses internally?
Thanks everyone!
Here is how we forced Storybook
^6.1to use PostCSS 8. (This presumes apostcss.config.jsfile at the root of your project. )First, install
postcss@^8andpostcss-loader@^4:Now, mutate your Storybook webpack config by creating/editing
.storybook/main.js:An explanation of what’s happening here:
postcss-loadercauses Webpack to use the module we installed above.I could workaround this by adding:
to my package.json.
With that I can successfully use Tailwind 2.0 inside storybook.
Edit: There is a better solution: https://github.com/storybookjs/storybook/issues/12668#issuecomment-730194625.
Having the exact same issue when trying to make my postcss config work. It won’t allow
postcss-importin my case. Is there a workaround? Can I upgrade those deps in storybook somehow?I tried
@storybook/addon-postcss."postcss": "8.2.4"However, I got an error that PostCSS 8 was not being used.
~
src/styles/global.css (“tailwindcss”: “2.0.2”)
Hey @aantipov at the end I didn’t need to use
resolutions. See my previous comment. Tailwind provides a compat version for PostCSS 7.The workaround with
resolutionsfield inpackage.jsonseems to work only foryarnusers. Npm doesn’t support it 😦 Forresolultionsto work with npm you need to install extra tool -npm-force-resolutions. I think I better wait for Storybook to migrate to latest PostcssI’m runnning Storybook 6.2.9 + NextJS 10 + Tailwind 2 and although the
addons-postcsssolution from https://github.com/storybookjs/storybook/issues/12668#issuecomment-773958085 allowed sb to build, upon visiting localhost:6006 it showsCannot GET /.What worked for me was downgrading tailwind as per https://github.com/storybookjs/storybook/issues/12668#issuecomment-730194625.
npx sb upgrade --prereleaseworked for me - it push it to^6.2.0-rc.0when I do
npx sb upgrade --prerelease, it does not affect my package.json at all. Am I doing upgrade in the wrong way? @shilmanHey @dazuaz I tried following your example repo but storybook still trigger tailwind build when ran. I understand your reasoning here but I don’t get how you stop tailwind from doing that. Still same error: PostCSS plugin tailwindcss requires PostCSS 8
Seems like for version bumps solution posted above might not be a feasible solution.
For the Tailwindcss version >
3.*.*and Storybook version >6.5.*along with postcss version of8.*, the followign steps worked or me:Adding the following import in the preview.js file under story book configuration.
Original Solution posted here
Overall setup:
Dependencies
.storybook/main.js
.storybook/preview.js
Hello all! I’m still having this issue after following several of the above suggested solutions. I’m wondering if it’s a version thing? Here’s what I’ve got:
package.json:
main.js
preview.js
It looks like all my versions are newer than the ones listed in the issue history here.
@larsenwork apologies. fixing with the release of
6.2.0-beta.7nowIn relation to
npx sb upgrade --prereleasenot resolving to the latest prerelease but to the latest release https://github.com/storybookjs/storybook/issues/12668#issuecomment-774505942 the package.json currently required to get things working isFor people just getting to this thread, https://github.com/storybookjs/storybook/issues/12668#issuecomment-773958085 is a guide on using new postcss with the prerelease of storybook 6.2
@dominikhaid this is already fixed in the prerelease + installing the
@storybook/addon-postcssmodule.@seonghyeonkimm sorry for the confusion.
--prereleaseupdates you to the most recently released version, which is the alpha version 99% of the time since I release alphas all the time. However, occasionally I release a patch version without releasing an alpha afterward, and then that becomes the upgrade target. It’s is a bug in the upgrade script, but a corner case.@danspratling Thanks for the guide! You are correct that
addon-postcssisn’t automatically added as a dependency when you upgrade because the deprecation is the only real “change”. Addingaddon-postcssis a solution for people that want to opt-in to using postcss (and then you can further configure it as outlined in your guide). Thanks again 😄@vdh did you try
@storybook/addon-postcssby @phated which is our proposed solution? Examples in the linked PR above.@shilman
@storybook/coreand@storybook/reactare still pinned to the very old version ofcss-loader(^3.0.0/^3.6.0), which pins to the olderpostcss^7version.Yippee!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.2.0-alpha.17 containing PR #13669 that references this issue. Upgrade today to the
@nextNPM tag to try it out!Closing this issue. Please re-open if you think there’s still more to do.
Yippee!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.2.0-alpha.16 containing PR #13655 that references this issue. Upgrade today to the
@nextNPM tag to try it out!Closing this issue. Please re-open if you think there’s still more to do.
^ I strongly agree with @trm217 😄 The most reliable workaround I think is the “resolution”, but even that requires us to use “yarn”. I know many people love yarn but in some environment we must use NPM…
@shilman the workaround for this problem seems to be unreliable (I did not manage to get any of the solutions mentioned in this thread working). In my opinion, the “has workaround” label should be removed.
I had the same issue in a project with postcss-mixins and postcss-nested. I ended up downgrading those packages to older versions for now (postcss-mixins 6.2.3 & postcss-nested 4.2.3).
I also had an issue with tailwind in storybook, ended up doing this ugliness, but it works: Import already compiled tailwind from node_modules
.storybook/preview.js:Specify somewhere that we are running a storybook
.storybook/main.js:Disable tailwind postcss plugin if running within a storybook context
postcss.config.js:Thank you @dazuaz, this approach fixed my issue.
I’m using Storybook with NextJS ( but not tailwind ) and I was facing this error:
The approach you show in your repo helped me getting rid of it.
@dazuaz It seems like storybook itself looks for
postcss.config.jsand triggers Tailwind when it sees Tailwind in the plugin list. I couldn’t get it to work even with a custom storybook Webpack config, storybook stills use the top-level PostCSS config. However, using Tailwind compat works, so that’s what I’m using for now.@kawinie Are you able to run
nextwithout any errors? ortailwind build ./styles/tailwind.css -o ./public/storybook/tailwind.storybook.css,make sure you check the examplespackage.jsonstorybook will trigger tailwind build if you import it in
.storybook/preview.jsAre you able to clone the repo and run it?
As a workaround for TailwindCSS, I opted to first, build out the CSS and then adding it to the <head> (
.storybook/preview-head.html), I think this method is more robust and easier to maintain. Example repo.Great news @eric-burel ! Awesome job figuring that out. Thanks to you we’re one step closer to a first class nextjs/storybook integration 🎉
The
styled-jsx-plugin-postcssissue is fixed by upgrading it to >3.0.2 (I was using v2), also upgraded Next 10.0.2. Now Storybook is building again. Thanks @shilman and @ndelangen for narrowing done the issue. I’ve now have a full working example of Next 10 + Storybook v6, including advanced features of Next like styled-jsx support.it was more of a tailwind issue than of tsdx. https://github.com/tailwindlabs/tailwindcss/issues/2795. got it working by commenting the
"@tailwind components"I was using tsdx for building a react component library and it is throwing errors even after setting up this for PostCSS 7. Got it working with non tsdx version easily with the sample @4lejandrito shared.
Hi, I’ve a similar issue with
styled-jsx-plugin-postcssandnext, where the build hangs instead of failing.(Non minimal) reproduction here: https://github.com/VulcanJS/vulcan-next/tree/bugfix/styled-jsx-postcss-storybook-build-fail, in
main.jswe can see that removing the plugin will make the build work againEdit: I’ve cross-posted to Next github where it is probably more suited.
@4lejandrito thanks you so much for taking the time to set up the sample repo for reference. I did try the instructions for post-css-7-compatibility-build… However, I was getting some weird errors… I am trying to use this as part of rushjs monorepo… Tried your repo and it is working perfectly fine… Will try to incorporate my stories to yours and see if it works…
@4lejandrito would you mind sharing your storybook setup or a sample repo on this setup… I am having trouble getting my tailwind 2.0 working with postcss@8