Skip to content

Vitest error import zone.js/testing after updating to v22 #33435

Description

@dkimmich-onventis

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

Description

After updating my zoneless Angular app, which uses the unit-test builder and the vitest runner, to v22, my unit tests fail with a zone.js related error. I narrowed it down to the installation of a dependency that has zone.js as a peer dependency, which makes the TestBed try to import zone.js, but this fails as I haven't installed it as a dependency in my zoneless app.

Minimal Reproduction

  1. Generate a fresh v22 zoneless app with pnpm as package manager
  2. Add a dependency that has zone.js as a peer dependency, i.e. ngx-markdown
  3. Run ng test

Exception or Error

Error: Failed to resolve import "zone.js/testing" from "init-testbed.js". Does the file exist?
  Plugin: vite:import-analysis
  File: /projects/ng-22-markdown/init-testbed.js:13:19
  13 |  var providers = [];
  14 |  if (typeof Zone !== "undefined") {
  15 |    await import("zone.js/testing");
     |                 ^
  16 |  }
  17 |  beforeEach(getCleanupHook(false));
 ❯ TransformPluginContext._formatLog node_modules/.pnpm/vite@7.3.5_sass@1.99.0/node_modules/vite/dist/node/chunks/config.js:29079:43
 ❯ TransformPluginContext.error node_modules/.pnpm/vite@7.3.5_sass@1.99.0/node_modules/vite/dist/node/chunks/config.js:29076:14
 ❯ normalizeUrl node_modules/.pnpm/vite@7.3.5_sass@1.99.0/node_modules/vite/dist/node/chunks/config.js:27199:18
 ❯ node_modules/.pnpm/vite@7.3.5_sass@1.99.0/node_modules/vite/dist/node/chunks/config.js:27257:32
 ❯ TransformPluginContext.transform node_modules/.pnpm/vite@7.3.5_sass@1.99.0/node_modules/vite/dist/node/chunks/config.js:27225:4
 ❯ EnvironmentPluginContainer.transform node_modules/.pnpm/vite@7.3.5_sass@1.99.0/node_modules/vite/dist/node/chunks/config.js:28877:14
 ❯ loadAndTransform node_modules/.pnpm/vite@7.3.5_sass@1.99.0/node_modules/vite/dist/node/chunks/config.js:22746:26

Your Environment

Angular CLI       : 22.0.3
Angular           : 22.0.2
Node.js           : 24.17.0
Package Manager   : pnpm 11.7.0
Operating System  : darwin arm64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 22.0.3            │ ^22.0.3           │
│ @angular/cli              │ 22.0.3            │ ^22.0.3           │
│ @angular/common           │ 22.0.2            │ ^22.0.0           │
│ @angular/compiler         │ 22.0.2            │ ^22.0.0           │
│ @angular/compiler-cli     │ 22.0.2            │ ^22.0.0           │
│ @angular/core             │ 22.0.2            │ ^22.0.0           │
│ @angular/forms            │ 22.0.2            │ ^22.0.0           │
│ @angular/platform-browser │ 22.0.2            │ ^22.0.0           │
│ @angular/router           │ 22.0.2            │ ^22.0.0           │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 6.0.3             │ ~6.0.2            │
│ vitest                    │ 4.1.9             │ ^4.0.8            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

Probably related: #32492

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions