Skip to content

unit-test builder fails to resolve nested imports in symlinked packages #33451

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/build:unit-test builder does not correctly handle local library dependencies installed via symlinks.

When a test target library imports another local library through a symlinked dependency, the test execution fails.

Attempting to enable symlink preservation using preserveSymlinks is not possible because this option is not supported by the @angular/build:unit-test schema.

Minimal Reproduction

Steps to reproduce

  1. Create a local library package-b.

  2. Create another local library package-a that imports and uses a reference exported by package-b.

  3. Build both libraries.

  4. Create a separate Angular workspace.

  5. Inside this workspace, create a third library package-c.

  6. Link the built versions of package-a and package-b into the new workspace node_modules using symlinks.

  7. Update package-c to import and use a reference from package-a.

  8. Add a unit test for package-c.

  9. Run:

ng test package-c

using the @angular/build:unit-test builder.

  1. The test execution fails.

Exception or Error

Error: Failed to resolve import "package-a" from "../../path/to/real/dist/package-b/fesm2022/package-b.mjs". Does the file exist?

Workaround

Developers are forced to manually alter tsconfig.spec.json to map internal node_modules paths to circumvent Vite's deep path resolution:

"compilerOptions": {
  "paths": {
    "package-a": ["../../node_modules/package-a"],
    "package-b": ["../../node_modules/package-b"]
  }
}

Your Environment

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

Angular CLI       : 22.0.4
Angular           : 22.0.2
Node.js           : 24.16.0
Package Manager   : npm 11.13.0
Operating System  : linux x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 22.0.4            │ ^22.0.4           │
│ @angular/cli              │ 22.0.4            │ ^22.0.4           │
│ @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/localize         │ 22.0.2            │ ^22.0.2           │
│ @angular/platform-browser │ 22.0.2            │ ^22.0.0           │
│ @angular/router           │ 22.0.2            │ ^22.0.0           │
│ ng-packagr                │ 22.0.0            │ ^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?

No response

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