Skip to content

Angular 15 fails with scss errors when building with browser:es-build  #24467

Closed

Description

@vmuresanu

Command

build

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

When trying to use es-build I get the following errors. Tried the solution specified in #24356, but it didn't work for me. Also found #24271 and other related issues, but still no luck.

[ERROR] [plugin angular-sass] Can't find stylesheet to import.
  ╷
1 │ @use 'colors' as *;
  │ ^^^^^^^^^^^^^^^^^^
  ╵
  src/app/ng-modules/containers/organization-management/containers/user-roles/dialogs/user-roles-modal.component.scss 1:1  root stylesheet


✘ [ERROR] [plugin angular-sass] Error: The "path" argument must be of type string. Received an instance of TypeError
  ╷
3 │ @use 'globals' as g;
  │ ^^^^^^^^^^^^^^^^^^^
  ╵
  src/styles/components/_mat-form-field.scss 3:1  @import
  src/styles/styles.scss 9:9                      root stylesheet

    angular:styles/global:styles:4:8:
      4 │ @import 'src/styles/styles.scss';
        ╵         ~~~~~~~~~~~~~~~~~~~~~~~~

Minimal Reproduction

ng build

Exception or Error

No response

Your Environment

Package                         Version
---------------------------------------------------------
@angular/core                   15.0.4
@angular-devkit/build-angular   15.0.4
rxjs                            7.8.0
typescript                      4.8.4

Anything else relevant?

No response

Activity

  1. clydin commented on Dec 27, 2022

    @clydin
    Member

    Can you provide the current value of the includePaths option for the project as well as the location of the global and colors files relative to the workspace root (the location of the angular.json file)?

  2. added
    needs: more info
    on Dec 27, 2022
  3. vmuresanu commented on Dec 28, 2022

    @vmuresanu
    Author

    Current value of includePaths -"includePaths": ["src/styles/variables"] - this works for regular build. For esbuild I tried to change to [""] and ["."] but still no luck
    Location of angular.json - <rootDir>/angular.json
    Location of global and color scss - <rootDir>/src/styles/variables

  4. clydin commented on Dec 28, 2022

    @clydin
    Member

    Is the ng build command being executed from the workspace root? I was able to reproduce the problem if the current working directory was not the workspace root. There appears to be a bug regarding the includePaths not always being resolved correctly in such cases.

  5. vmuresanu commented on Dec 30, 2022

    @vmuresanu
    Author

    Tried it again to double check and yes - ng build is being executed from the workspace root.

  6. gitromain commented on Jan 12, 2023

    @gitromain

    Hello, I had the same problem, I changed @use "src/styles/variables"; to @use "src/styles/variables.scss";
    It solved the "Can't find stylesheet to import" problem.

    But then it seems that some variables are no longer found :

    X [ERROR] [plugin angular-sass] Undefined variable. ╷ 83 │ background: $color-primary-01-500; │ ^^^^^^^^^^^^^^^^^^^^^ ╵ src\app\pages\attributes-campaign\attributes-campaign-creation\attributes-campaign-creation.component.scss 83:15 root stylesheet

  7. clydin commented on Jan 12, 2023

    @clydin
    Member

    Unfortunately, we have been unable to reproduce the issue as described. If you could provide a minimal reproduction of the issue, we can troubleshoot further.
    Also, please try with the latest version of the CLI (currently 15.1.1) to see if that resolves the problem.

  8. monkeycatdog commented on Jan 17, 2023

    @monkeycatdog

    I have the same problem under my gitlab pipeline. Locally I cannot reproduce it, but under pipeline it appears sometimes. No idea what’s going on

  9. added
    needs: repro steps
    on Jan 17, 2023
  10. monkeycatdog commented on Jan 17, 2023

    @monkeycatdog
    HookWebpackError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
    SassError: Undefined function.
       ╷
    78 │   @if custom-properties.is-custom-prop($px) {
       │       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       ╵
      @material/elevation/_typography.scss 78:7                                  px-to-rem()
      @material/elevation/_typography.scss 132:18                                @use
      node_modules/@material/button/_button-base.scss 26:1                       @use
      @px/ui-styles-utils/_button.scss 30:1                                      @forward
      node_modules/@mds/styles/src/lib/vendor/_ui-styles-utils.scss 1:1          @use
      node_modules/@mds/styles/src/lib/mixins/components/button/_base.scss 2:1   @use
      node_modules/@mds/styles/src/lib/mixins/components/button/_fab.scss 1:1    @forward
      node_modules/@mds/styles/src/lib/mixins/components/button/_index.scss 1:1  @forward
      node_modules/@mds/styles/src/lib/mixins/components/_index.scss 1:1         @forward
      node_modules/@mds/styles/src/lib/mixins/_index.scss 1:1                    @forward
      node_modules/@mds/styles/src/_index.scss 1:1                               @forward
      @material/button/index.scss 1:1                                            @use
      node_modules/@angular/material/button/_button-theme.scss 2:1               @use
      node_modules/@angular/material/core/density/private/_all-density.scss 2:1  @forward
    
  11. alan-agius4 commented on Jan 17, 2023

    @alan-agius4
    Collaborator

    Unfortunately without a reproduction we are unable to look into this issue any further.

    You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

  12. clydin commented on Jan 17, 2023

    @clydin
    Member

    @monkeycatdog The error you provided is from a Webpack based build (@angular-devkit/build-angular:browser). This issue is about the experimental esbuild-based builder (@angular-devkit/build-angular:browser-esbuild).
    Please open a separate issue if you are encountering problems with the default builder.

  13. vmuresanu commented on Jan 18, 2023

    @vmuresanu
    Author

    I have reproduced the issue - https://github.com/vmuresanu/Repro-App . Like I stated in original issue, the problem is in

    "stylePreprocessorOptions": {
       "includePaths": ["src/styles/variables"]
    },

    What it does is it allows to use short syntax:
    @use "globals" as *
    But if I point to relative path - @use "./../styles/variables/globals" as g; es-build works. So it is definitely the problem in stylePreprocessorOptions.

    Steps to Reproduce:

    1. ng build with - browser-esbuild - observe the error
    2. ng build with browser - the is no errors
  14. alan-agius4 commented on Jan 18, 2023

    @alan-agius4
    Collaborator

    Thanks for the repro @vmuresanu.

    What is happening here is that global in being resolved incorrectly as a node package even though it does not export any CSS.

    Code:

    const packageResult = await resolveUrl(
    packageName + '/package.json',
    previousResolvedModules,
    );
    if (packageResult.path) {
    return pathToFileURL(
    join(dirname(packageResult.path), !hasScope ? nameOrFirstPath : '', ...pathPart),
    );
    }

  15. added
    freq1: low
    and removed
    needs: repro steps
    on Jan 18, 2023
  16. angular-automatic-lock-bot commented on Feb 19, 2023

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  17. locked and limited conversation to collaborators on Feb 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions