nx icon indicating copy to clipboard operation
nx copied to clipboard

Angular unit tests fail: Must use import to load ES Module

Open Nosfistis opened this issue 1 month ago • 1 comments

Current Behavior

After generating a new workspace with nx and an angular application with jest testing, the nx test command fails with:

Must use import to load ES Module: ..\node_modules\@angular\core\fesm2022\testing.mjs
    > 1 | import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
        | ^
      2 |
      3 | setupZoneTestEnv({
      4 |   errorOnUnknownElements: true,
      at Runtime.requireModule (../../node_modules/jest-runtime/build/index.js:850:21)
      at Object.<anonymous> (../../node_modules/jest-preset-angular/setup-env/zone/index.js:4:24)

Expected Behavior

The jest test should pass in a new workspace.

GitHub Repo

The examples do not use the latest setup-env/zone.

Steps to Reproduce

  1. Generate a new nx workspace.
  2. Add an angular application (test-app) to the workspace, which uses jest as test runner.
  3. Run npx test test-app.
  4. The jest tests fail.

Nx Report

Node           : 22.12.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 10.9.0

nx                     : 22.0.2
@nx/js                 : 22.0.2
@nx/jest               : 22.0.2
@nx/eslint             : 22.0.2
@nx/workspace          : 22.0.2
@nx/angular            : 22.0.2
@nx/devkit             : 22.0.2
@nx/eslint-plugin      : 22.0.2
@nx/module-federation  : 22.0.2
@nx/nest               : 22.0.2
@nx/node               : 22.0.2
@nx/rspack             : 22.0.2
@nx/web                : 22.0.2
@nx/webpack            : 22.0.2
@nx/docker             : 22.0.2
typescript             : 5.9.3
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
---------------------------------------
Community plugins:
angular-eslint : 20.5.1
---------------------------------------
Cache Usage: 113.50 KB / 93.06 GB

Failure Logs


Package Manager Version

No response

Operating System

  • [ ] macOS
  • [ ] Linux
  • [x] Windows
  • [ ] Other (Please specify)

Additional Information

No response

Nosfistis avatar Nov 03 '25 15:11 Nosfistis