Skip to content

@angular/build: ng test fails on Windows — setupFiles path not normalized to POSIX, breaks import resolution #33749

Description

@aquesada-planhub

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 — unit-test/Vitest builder is new; broken on Windows since it shipped

Description

Windows-only Failed to resolve import in vite:import-analysis; root-cause table (spec keys POSIX via toPosixPath vs setup-file key backslashes via path.join) → map miss → raw-source cascade; the one-line toPosixPath fix diff; note on why resolve.alias isn't a valid workaround

Minimal Reproduction

  1. ng new repro --defaults --style=css --routing=false
  2. cd repro

Then:

  • tsconfig alias — add "paths": { "@lib/*": ["src/lib/*"] } and "baseURL" to tsconfig.json
  • aliased module — src/lib/greeting.ts → export const greeting = 'hello';
  • setup file — src/test-setup.ts → import { greeting } from '@lib/greeting';
  • wire the builder in angular.json under the project's test target:
"test": {
  "builder": "@angular/build:unit-test",
  "options": {
    "buildTarget": "repro:build:development",
    "tsConfig": "tsconfig.spec.json",
    "runner": "vitest",
    "setupFiles": ["src/test-setup.ts"]
  }
}
  • run: ng test

Expected: alias resolves (as it does at build time), tests run.

Actual (Windows): Failed to resolve import "@lib/greeting" from "src/test-setup.ts" — Plugin: vite:import-analysis, 0 tests. Same repo passes on macOS/Linux.

Exception or Error

Error: Failed to resolve import "@lib/greeting" from "src/test-setup.ts". Does the file exist?
Plugin: vite:import-analysis
Image

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI       : 22.0.3
Angular           : 22.0.2
Node.js           : 22.22.3
Package Manager   : npm 12.0.2
Operating System  : win32 x64

┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package                           │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/architect         │ 0.2200.3          │ 0.2200.3          │
│ @angular-devkit/build-angular     │ 22.0.3            │ ^22.0.3           │
│ @angular-devkit/core              │ 22.0.3            │ ^22.0.3           │
│ @angular/animations               │ 22.0.2            │ ^22.0.2           │
│ @angular/build                    │ 22.0.6            │ ^22.0.6           │
│ @angular/cdk                      │ 22.0.2            │ ^22.0.2           │
│ @angular/cli                      │ 22.0.3            │ ^22.0.3           │
│ @angular/common                   │ 22.0.2            │ ^22.0.2           │
│ @angular/compiler                 │ 22.0.2            │ ^22.0.2           │
│ @angular/compiler-cli             │ 22.0.2            │ ^22.0.2           │
│ @angular/core                     │ 22.0.2            │ ^22.0.2           │
│ @angular/elements                 │ 22.0.2            │ ^22.0.2           │
│ @angular/forms                    │ 22.0.2            │ ^22.0.2           │
│ @angular/google-maps              │ 22.0.2            │ ^22.0.2           │
│ @angular/localize                 │ 22.0.2            │ ^22.0.2           │
│ @angular/material                 │ 22.0.2            │ ^22.0.2           │
│ @angular/platform-browser         │ 22.0.2            │ ^22.0.2           │
│ @angular/platform-browser-dynamic │ 22.0.2            │ ^22.0.2           │
│ @angular/router                   │ 22.0.2            │ ^22.0.2           │
│ ng-packagr                        │ 22.0.0            │ ^22.0.0           │
│ rxjs                              │ 7.8.2             │ ~7.8.0            │
│ typescript                        │ 6.0.3             │ ~6.0.0            │
│ vitest                            │ 4.1.10            │ ^4.1.10           │
│ zone.js                           │ 0.16.2            │ ~0.16.0           │
└───────────────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

Windows-only, only setup files importing first-party modules, patch-package verification numbers

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions