question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Global style not loaded in Angular

See original GitHub issue

Describe the bug I want to include a stylesheet file in my stories globally. However, the file is not loaded. My angular.json looks like this (the last line contains the style inclusion):

{
    "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "my-project": {
            "root": "..",
            "sourceRoot": ".",
            "projectType": "application",
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        "outputPath": "dist",
                        "index": "./components/root/static/index.html",
                        "main": "./app.entry.ts",
                        "tsConfig": "./tsconfig.json",
                        "polyfills": "./app/app.dependencies.ts",
                        "assets": ["app/assets"],
                        "styles": ["app/assets/style/style.scss"],

System:

  • OS: MacOS
  • Browser: chrome
  • Framework: angular 7.2
  • Version: Storybook 4.1.4

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:24
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
mrkpkscommented, Jan 17, 2019

Same problem with Storybook 4.1.6. Tried various solutions with webpack.config.ts but nothing worked. Component styles are loaded fine.

  • sass-loader used by storybook cannot resolve global styles (and global imports inside components).
  • component styles are untouched if no global styles are used inside

Main problem: using global imports inside of a component e.g. @import '~src/styles/variables or @import 'variables' will end up with storybook compilation error:

ERROR in ./src/app/tab2/example/example.component.scss Module build failed (from ./node_modules/sass-loader/lib/loader.js):

Either File to import not found or unreadable: ~src/styles/variables. or File to import not found or unreadable: variables.

PS I have set preprocessor options like this:

"stylePreprocessorOptions": {
  "includePaths": [
    "src",
    "src/styles"
  ]
},
10reactions
MarkoSulamagicommented, Feb 4, 2019

Hey, any updates on this? We had to downgrade 2 angular devkit packages so storybook could read angular.json. But this isn’t really a viable solution.

Storybook can read angular.json with the following packages

    "@angular-devkit/build-angular": "~0.10.7",
    "@angular-devkit/build-ng-packagr": "~0.10.7",
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 13. Global styles no longer work in SB 6.4 (CSS or ...
Styles in Angular project are now included into the SB build and it is working. Issues still to be resolved: External static styles,...
Read more >
angular-cli how to add global styles? - Stack Overflow
Copy the global styles into src/styles.css · Use CSS imports to import external rules into styles.css · Add more global styles via the...
Read more >
Angular Global CSS styles - TekTutorialsHub
There are several ways to add Global (Application wide styles) styles to the Angular application. The styles can be added inline, ...
Read more >
Component styles - Angular
While Angular's default style encapsulation prevents component styles from affecting other components, global styles affect all components on the page. This ...
Read more >
Avoid global styles in your Angular projects
Avoid global styles in your Angular projects · break encapsulation · poor readability · break information hiding · namespace pollution.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found