1

I have an angular v20 project.

I have implemented a class "redborder" in "src/styles.scss" file and I am trying to @use the "redborder" class from a component style file but Angular can't find the global styles.scss file to import.

Example code below. I tried again on a newly created project. I can extend to "blackborder" class in the app.scss file and it is working okay. But when I try to extend to "redborder" class, I am getting this error. "Can't find stylesheet to import."

app.html

<div class="test">hello</div>

app.scss

@use "src/styles";

.blackborder {

    border: 1px solid red;

}

.test {

    @extend .redborder;
    @extend .blackborder;

}

src/styles.scss

.redborder {

    border: 1px solid red;

}
2
  • 2
    please share the minimal reproducible code, if possible a stackblitz with the issue happening Commented Nov 25 at 8:04
  • Added minimal code and extra explanation. The issue is reproducable on a new project also Commented Nov 25 at 11:16

2 Answers 2

2

You're using "relative path" so, e.g., if "styles.sccs" and "app.scss" are in the same folder:

@use "./styles";
//or
@use "styles";

(not include the src)

NOTE: In angular.json, you can see in "projects"--> "architect"-->"build"-->"styles" some like

"styles": ["src/styles.css"],

This "styles" is an array of files (see again that you use relative path, as angular.json is in the root, in this file you use "src/styles.css" and this styles will be global to all the application (it's not necesary include in each component.css using @use

stackblitz

Sign up to request clarification or add additional context in comments.

3 Comments

It is true that classes in styles.scss file are accessible in all html files. But I want to keep the html files clean and only extend on scss files. On the other hand, it appears to be that @use syntax is not working on absolute path, as in the first block
I made a stackblitz with your code (using relative path) and work. BTW,
Okay. I found a solution, though it is a bit of a rough solution. By the help of below. Answer is added. stackoverflow.com/questions/42865697/… angular.dev/reference/configs/…
1

I found a rough solution by following here.
https://angular.dev/reference/configs/workspace-config#style-preprocessor-options

In the example, it was to a different direction (src/style-paths). I solved it by including the "src" directory itself.

{
  "projects": {
    "my-app": {
      "architect": {
        "build": {
          "builder": "@angular/build:application",
          "options": {
            "stylePreprocessorOptions": {
              "includePaths": [
                "src"
              ]
            }
          }
        }
      }
    }
  }
}

Ref to another relevant question.
SCSS Import Relative to Root

1 Comment

Thanks to share the solution (I was going to answer that same thing but I happy you find the solution :))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.