Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular / Storybook: styles.scss of the default project is used for all storybook configs #8255

Closed
simpros opened this issue Dec 21, 2021 · 22 comments
Assignees
Labels
outdated scope: storybook Issues related to Storybook support in Nx type: bug

Comments

@simpros
Copy link

simpros commented Dec 21, 2021

Current Behavior

After adding storybook-config to a library, the styles.scss of the default application (specified in nx.json) will be applied to all stories.

Expected Behavior

The storybook styling should be independent of any application styling

Steps to Reproduce

  1. Create a new nx workspace with the angular preset.
  2. Add a library to the workspace
  3. Create an component in the library
  4. Add the storybook-configuration for the library
  5. Run storybook for the library
  6. Change the styling in the app´s styles.scss

I have created an demo repository for easier reproduction

Environment

  Node : 14.17.0
  OS   : darwin x64
  yarn : 1.22.17
  
  nx : 13.3.5
  @nrwl/angular : 13.3.5
  @nrwl/cli : 13.3.5
  @nrwl/cypress : 13.3.5
  @nrwl/devkit : 13.3.5
  @nrwl/eslint-plugin-nx : 13.3.5
  @nrwl/express : undefined
  @nrwl/jest : 13.3.5
  @nrwl/linter : 13.3.5
  @nrwl/nest : undefined
  @nrwl/next : undefined
  @nrwl/node : undefined
  @nrwl/nx-cloud : undefined
  @nrwl/react : undefined
  @nrwl/react-native : undefined
  @nrwl/schematics : undefined
  @nrwl/tao : 13.3.5
  @nrwl/web : undefined
  @nrwl/workspace : 13.3.5
  @nrwl/storybook : 13.3.11
  @nrwl/gatsby : undefined
  typescript : 4.4.4
  rxjs : 7.4.0
  ---------------------------------------
  Community plugins:
         @angular/animations: 13.1.1
         @angular/cdk: 13.1.1
         @angular/common: 13.1.1
         @angular/compiler: 13.1.1
         @angular/core: 13.1.1
         @angular/forms: 13.1.1
         @angular/material: 13.1.1
         @angular/platform-browser: 13.1.1
         @angular/platform-browser-dynamic: 13.1.1
         @angular/router: 13.1.1
         @angular-devkit/build-angular: 13.0.4
         @angular/cli: 13.0.4
         @angular/compiler-cli: 13.1.1
         @angular/language-service: 13.1.1
         @storybook/angular: 6.4.9
@joewIST
Copy link

joewIST commented Dec 22, 2021

I am also experiencing this issue. No matter what I use for browserTarget in angular.json, the defaultProject in nx.json is always used in the storybook build, which means any global styles (in the library's styles array in angular.json) are not applied. I haven't been able to find an adequate workaround yet (other than needlessly adding irrelevant stylesheets to the defaultProject's styles array. Any tips?

@mandarini
Copy link
Member

Hi there! Thank you @CodeCakePie @joewIST for filing this issue!

Can you try setting the --projectBuildConfig flag to the project you want the use the styles from when you're running/building Storybook, and let me know if your issue is resolved?

eg.

nx storybook your-project-name --projectBuildConfig="your-project-name"

or

nx build-storybook your-project-name --projectBuildConfig="your-project-name"

@mandarini mandarini added the scope: storybook Issues related to Storybook support in Nx label Dec 23, 2021
@mandarini mandarini self-assigned this Dec 23, 2021
@mandarini
Copy link
Member

btw, maybe a small adjustment in the codebase, and some documentation will land at some point in January to make this a bit clearer.

@mandarini
Copy link
Member

Linking this for reference #8199

@joewIST
Copy link

joewIST commented Jan 4, 2022

@mandarini yes that fixes things, thank you. i was unable to find any reference to this projectBuildConfig before

@mandarini
Copy link
Member

That's great @joewIST ! I will go ahead and close this issue for now. If it ever comes up again, I'll make sure to open it up! :) Thank you!

@joewIST
Copy link

joewIST commented Jan 4, 2022

unfortunately i now get a new issue which means it can't even build at all: TypeError: getTypescriptWorkerPlugin is not a function

@mandarini
Copy link
Member

mandarini commented Jan 4, 2022

@joewIST Ohh that's the Storybook Angular 13.1 bug! You should be good if you upgrade Storybook to the pre-release version, as mentioned here.

@joewIST
Copy link

joewIST commented Jan 4, 2022

hi @mandarini that does not fix things i'm afraid

@mandarini
Copy link
Member

The "TypeError: getTypescriptWorkerPlugin is not a function" is a bug on the Storybook side. Storybook v6.4.9 does not work with Angular 13.1, because Storybook v.6.4.9 references the getTypescriptWorkerPlugin from Angular, which, in version 13.1 has been renamed to getDevServerConfig. Can you try what is suggested here in this comment? This should definitely fix that exact issue. And let me know what you get!

@rfprod
Copy link
Contributor

rfprod commented Jan 4, 2022

The "TypeError: getTypescriptWorkerPlugin is not a function" is a bug on the Storybook side. Storybook v6.4.9 does not work with Angular 13.1, because Storybook v.6.4.9 references the getTypescriptWorkerPlugin from Angular, which, in version 13.1 has been renamed to getDevServerConfig. Can you try what is suggested here in this comment? This should definitely fix that exact issue. And let me know what you get!

@mandarini https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.6 works
Configs -> storybookjs/storybook#16977 (comment)

@joewIST
Copy link

joewIST commented Jan 4, 2022

hi @mandarini i have tried that solution and now get the following error:

ModuleParseError: Module parse failed: Unexpected token (3:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

@mandarini
Copy link
Member

Hmmm I am worried that this may be on the Storybook side @joewIST ! Can you read through the above issue to see if there's anything reported that matches your case?

@joewIST
Copy link

joewIST commented Jan 4, 2022

i will have a look thanks, there seem to be so many issues re: storybook/nx/angular integration atm!

@mandarini
Copy link
Member

Indeed.. We'll get there! :)

@mandarini
Copy link
Member

@joewIST Another potential solution would be do undo the changes to the storybook side that you did, and downgrade Angular to 13.0? I am not 100% sure, but maybe it could help you get going in the meantime, while a solid fix is in place?
@rfprod wdyt?

@joewIST
Copy link

joewIST commented Jan 4, 2022

@mandarini i'm going to try to investigate whatever storybook issues might be causing this and if i can't find anything i'll have to park this for now. i've already spent so much time trying to upgrade to angular v13 these last few weeks

@mandarini
Copy link
Member

Sounds good @joewIST ! I am sorry I could not help you any further. We're all trying our best to fix these issues. I will post any potential updates here. Good luck! :)

@rfprod
Copy link
Contributor

rfprod commented Jan 4, 2022

@joewIST Another potential solution would be do undo the changes to the storybook side that you did, and downgrade Angular to 13.0? I am not 100% sure, but maybe it could help you get going in the meantime, while a solid fix is in place? @rfprod wdyt?

@mandarini If you want my opinion, it seems to me that it makes sense to downgrade to Angular 13.0 as a default version until storybook 6.5.0 is released, so that newly created projects work out of the box. However, I don't see any issues tweaking configs to be able to use the latest versions. It's time consuming for sure, but it pays off imo.

@mandarini
Copy link
Member

Thanks @rfprod ! :)

@mandarini
Copy link
Member

New docs for styles and stylePreprocessorOptions

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: storybook Issues related to Storybook support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

4 participants