Command
test
Is this a regression?
The previous version in which this bug was not present was
No response
Description
The Angular unit test builder allows providing a custom Vitest configuration.
However, options such as optimizeDeps.exclude do not appear to be applied.
This becomes a problem when testing in Browser Mode with dependencies that rely on module side effects. These packages need to be excluded from Vite's dependency optimization so they are loaded as-is.
For example:
export default defineConfig({
optimizeDeps: {
exclude: ['my-package'],
},
});
When running the tests through the Angular builder, this configuration appears to be ignored.
As a result, Vite pre-bundles the dependency and the package fails to initialize correctly, causing the tests to fail during module loading.
Minimal Reproduction
-
Create a new Angular workspace.
-
Generate a library:
ng generate library my-lib
-
Generate a Vitest configuration for the library:
ng generate vitest-config my-lib
-
Install a package that relies on module side effects (for example @progress/kendo-ui).
-
Add the package to optimizeDeps.exclude in the generated Vitest config:
export default defineConfig({
optimizeDeps: {
exclude: ['@progress/kendo-ui'],
},
});
-
Create a test that imports the package.
-
Run the tests in Browser Mode.
Exception or Error
Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI : 22.0.5
Angular : 22.0.5
Node.js : 24.16.0
Package Manager : npm 11.13.0
Operating System : linux x64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/animations │ 22.0.5 │ ^22.0.5 │
│ @angular/build │ 22.0.5 │ ^22.0.5 │
│ @angular/cli │ 22.0.5 │ ^22.0.5 │
│ @angular/common │ 22.0.5 │ ^22.0.5 │
│ @angular/compiler │ 22.0.5 │ ^22.0.5 │
│ @angular/compiler-cli │ 22.0.5 │ ^22.0.5 │
│ @angular/core │ 22.0.5 │ ^22.0.5 │
│ @angular/forms │ 22.0.5 │ ^22.0.5 │
│ @angular/localize │ 22.0.5 │ ^22.0.5 │
│ @angular/platform-browser │ 22.0.5 │ ^22.0.5 │
│ @angular/router │ 22.0.5 │ ^22.0.5 │
│ @angular/service-worker │ 22.0.5 │ ^22.0.5 │
│ ng-packagr │ 22.0.1 │ ^22.0.1 │
│ rxjs │ 7.8.2 │ ~7.8.2 │
│ typescript │ 6.0.3 │ ^6.0.3 │
│ vitest │ 4.1.9 │ ^4.0.0 │
│ zone.js │ 0.16.2 │ ~0.16.2 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else relevant?
No response
Command
test
Is this a regression?
The previous version in which this bug was not present was
No response
Description
The Angular unit test builder allows providing a custom Vitest configuration.
However, options such as
optimizeDeps.excludedo not appear to be applied.This becomes a problem when testing in Browser Mode with dependencies that rely on module side effects. These packages need to be excluded from Vite's dependency optimization so they are loaded as-is.
For example:
When running the tests through the Angular builder, this configuration appears to be ignored.
As a result, Vite pre-bundles the dependency and the package fails to initialize correctly, causing the tests to fail during module loading.
Minimal Reproduction
Create a new Angular workspace.
Generate a library:
Generate a Vitest configuration for the library:
Install a package that relies on module side effects (for example
@progress/kendo-ui).Add the package to
optimizeDeps.excludein the generated Vitest config:Create a test that imports the package.
Run the tests in Browser Mode.
Exception or Error
Your Environment
Anything else relevant?
No response