Skip to content

Vitest config options (e.g. optimizeDeps) are ignored by the Angular unit test builder #33507

Description

@Carlosamouco

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

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

  1. Create a new Angular workspace.

  2. Generate a library:

    ng generate library my-lib
  3. Generate a Vitest configuration for the library:

    ng generate vitest-config my-lib
  4. Install a package that relies on module side effects (for example @progress/kendo-ui).

  5. Add the package to optimizeDeps.exclude in the generated Vitest config:

    export default defineConfig({
      optimizeDeps: {
        exclude: ['@progress/kendo-ui'],
      },
    });
  6. Create a test that imports the package.

  7. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions