Skip to content

@angular-devkit/build-angular:application does not support sass imports in monorepo #27162

@csaszika

Description

@csaszika

Command

build, serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

With @angular-devkit/build-angular:browser executor the build worked. Sass imports also worked if I used this way:

@use 'libs/shared/components/src' as components;

With @angular-devkit/build-angular:application, the build is failed because of:

[ERROR] Can't find stylesheet to import.
 ╷
2 │ @use 'libs/shared/components/src' as components;
 │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 ╵
 apps/scaffold/src/styles.scss 1:1  root stylesheet [plugin angular-sass]

With style including option I'm able to include third party css libs and monorepo libs as well, but I have to change the path everywhere in apps and in libs as well to relative paths instead of using paths from root:

libs/shared/css-lib -> ../../../libs/shared/css-lib OR ../../../../../libs/shared/css-lib

Desired solution:
Changing to @angular-devkit/build-angular:application executor could use the same css imports:

@use 'libs/shared/components/src' as components;

OR same imports what we can use in ts files;

@use '@shared/lib' as components;

Minimal Reproduction

  1. Create a monorepo (with nx)
  2. create an app
  3. create a sass library
  4. use the sass library css inside the app with path libs/path/to/lib or with @shared/lib
  5. see error in console after run build target

Exception or Error

[ERROR] Can't find stylesheet to import.
  ╷
2 │ @use 'libs/shared/components/src' as components;
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  apps/scaffold/src/styles.scss 1:1  root stylesheet [plugin angular-sass]

Your Environment

@angular/xxx        -> 17.1.1.
@angular-devkit/xxx -> 17.1.1
@nx/angular         -> 18.0.1.

Anything else relevant?

With @angular-devkit/build-angular:browser-esbuild the result is the same. Perhaps it is the same issue in both cases.
Probably these esbuild based executors are not prepared to sass/css imports in a monorepo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions