Skip to content

Error when running test with vitest after upgrading from v21.0 to v21.1 #32305

@JulienMichelFr

Description

@JulienMichelFr

Command

test

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

21.0

Description

With the latest v21.1.0 version, it's now impossible to run unit-test with vitest when there is scss assets in ng-package.json
When running the command ng test, the CLI will stop with error

Error: The {scss file listed in ng-package.json} asset path must start with the project source root.                                                                                                                                                                                                                                

Minimal Reproduction

I've created a repo with two tags:

You just have to install and then run ng test ui

Exception or Error

An exception occurred while creating the test executor:
Error: The ./src/lib/theme.scss asset path must start with the project source root.                                                                                                                                                                                                                                
    at /{path-to-repo}/repro-angular-library-vitest-bug/node_modules/@angular/build/src/utils/normalize-asset-patterns.js:71:23                                                                                                                                                                   
    at Array.map (<anonymous>)                                                                                                                                                                                                                                                                                     
    at normalizeAssetPatterns (/{path-to-repo}/repro-angular-library-vitest-bug/node_modules/@angular/build/src/utils/normalize-asset-patterns.js:64:26)                                                                                                                                          
    at normalizeOptions (/{path-to-repo}/repro-angular-library-vitest-bug/node_modules/@angular/build/src/builders/application/options.js:77:46)                                                                                                                                                  
    at async buildApplicationInternal (/{path-to-repo}/repro-angular-library-vitest-bug/node_modules/@angular/build/src/builders/application/index.js:86:31)                                                                                                                                      
    at async runBuildAndTest (/{path-to-repo}/repro-angular-library-vitest-bug/node_modules/@angular/build/src/builders/unit-test/builder.js:158:22)                                                                                                                                              
    at async execute (/{path-to-repo}/repro-angular-library-vitest-bug/node_modules/@angular/build/src/builders/unit-test/builder.js:330:13)                                                                                                                                                      
    at async handleAsyncIterator (/{path-to-repo}/repro-angular-library-vitest-bug/node_modules/@angular-devkit/architect/src/api.js:38:28)

Your Environment

Angular CLI       : 21.1.0
Angular           : 21.1.0
Node.js           : 24.11.1
Package Manager   : npm 11.7.0
Operating System  : linux x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 21.1.0            │ 21.1.0            │
│ @angular/cli              │ 21.1.0            │ 21.1.0            │
│ @angular/common           │ 21.1.0            │ 21.1.0            │
│ @angular/compiler         │ 21.1.0            │ 21.1.0            │
│ @angular/compiler-cli     │ 21.1.0            │ 21.1.0            │
│ @angular/core             │ 21.1.0            │ 21.1.0            │
│ @angular/forms            │ 21.1.0            │ 21.1.0            │
│ @angular/platform-browser │ 21.1.0            │ 21.1.0            │
│ @angular/router           │ 21.1.0            │ 21.1.0            │
│ ng-packagr                │ 21.1.0            │ 21.1.0            │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 5.9.3             │ ~5.9.2            │
│ vitest                    │ 4.0.17            │ ^4.0.8            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

No response

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