nx
nx copied to clipboard
Angular unit tests fail: Must use import to load ES Module
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
- Generate a new nx workspace.
- Add an angular application (
test-app) to the workspace, which uses jest as test runner. - Run
npx test test-app. - 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