storybook: Reopened bug. Angular 13. Global styles no longer work in SB 6.4 (CSS or SCSS)
Original bug is not resolved https://github.com/storybookjs/storybook/issues/16802
NOTE: for those who landed here please refer to the original issue for a workaround. It does work
Attaching updated project to reproduce the issue.
Describe the bug
- Clean NG 13 project + SB 6.4.8
- Added global plain old CSS style as described in https://storybook.js.org/docs/angular/configure/styling-and-css#importing-css-files
- Result. No global styles applied.
To Reproduce
Attaching a minimal reproduction generated myself as npx sb@next repro fails. styles_issue_repro 2.zip
Just run the below to see the reproduction of the issue
npm i && npm run storybook
Expected result
Global styles should apply, i.e.
- All divs must have a red background
- A top div in http://localhost:6006/?path=/story/example-introduction--page must have a blue background
System
macOS Monterey OS Version 12.0.1 npm 6.14.15 node v14.18.1
Additional context n/a
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 20 (3 by maintainers)
For anyone still experiencing this issue, a hacky workaround seems to be manually appending whatever global styles you need in the preview.js:
For context, this is the preview.js inside an nx monorepo library. I have tried with (no luck) to add styles to the project’s styles array in angular.json, but nothing is ever loaded. This is holding back our upgrade to v.13 so would be useful if there was a fix/better workaround for loading global styles.
Also, fwiw, the migration guide approach isn’t working for my
@nrwl/nxbased project (which is probably the second most popular way to manage Angular projects at this point). So tried following with nothing landing on the SB rendered pages:I tried the preview hack and the
<style>tag isn’t even showing up on the pageSo it doesn’t seem like the Migration guide approach is working for
nx monorepobased libraries as also mentioned by @joewIST above:Perhaps it’s something to do with
"builder": "@nrwl/storybook:storybook",being different then ng one I dunno.UPDATE: I got it working! For others maybe you’ll run in to this and it’ll help
In you’re
angular.jsonyou’ll see two storybook stanzas like:"storybook": {}"build-storybook": {}For me these styles didn’t show up until I put them in the
build-storybookone. I haven’t dug in, but I’m assuming the first utilizes the later to “build storybook”. The following verbose paste with both you’ll notice I now only have the styles in the build storybook stanza (which IS working):@mandarini never mind. I have figured out.
For anyone having the same issue in the future. Checkout the branch I created in my demo repo
To run the whole storybook, I use a wrapper app to run all stories from each library
https://github.com/maxisam/nx-storybook-demo/tree/sb-app-global-style
To run the individual library.
https://github.com/maxisam/nx-storybook-demo/tree/sb-lib-global-style
I don’t think we need to include styles in the build-storybook config anymore as @roblevintennis comments.
Yeah that’s what got things working for me (and it looks like others). Nothing else wrong that I can think of at the moment (on my phone away from my machine) but perhaps you can document it in an aside note in the upgrade to 13 nx docs. Might help for folks upgrading angular via nx.
Hi there @roblevintennis ! Katerina from Nx team here. Let me understand the issue a bit better. Adding the styles in the
build-storybooktarget makes it work, right? Is there any other issue you’re experiencing using Nx & Storybook & Angular?I can confirm that the solution of @roblevintennis in the
UPDATEsection right above here works, also for.scssfiles.This is still an issue for me. Global styles and CSS variables are not being picked up at all, nor are any styles pulled from node modules