nx: Jest in Angular workspace can not find paths to libraries
After 14.1.6, Jest can not translate “@orgPrefix/libName” into a path. Reproducible with 14.1.6 and 14.1.7-beta.2.
Current Behavior
Application test error:
FAIL appName apps/appName/src/app/[..]/task-images/task-images.component.spec.ts
● Test suite failed to run appName/src/app/[..]/upload-page.component.spec.ts
Cannot find module '@scs/api' from 'src/app/[..]/task-images/task-images.component.ts'
Require stack:
src/app/[..]/task-images/task-images.component.ts
src/app/[..]/task-images/task-images.component.spec.ts
1 | import { Component, ChangeDetectionStrategy, NgModule, Input, Output, EventEmitter } from '@angular/core';
> 2 | import { PermissionService } from '@scs/api';
| ^
Library test error:
FAIL inputs libs/inputs/src/lib/standard-input/standard-input.component.spec.ts
● Test suite failed to run
Cannot find module '@scs/api' from 'src/lib/enums.ts'
Require stack:
src/lib/enums.ts
src/lib/inputs.service.ts
src/lib/base-input.component.ts
src/lib/standard-input/standard-input.component.ts
src/lib/standard-input/standard-input.component.spec.ts
> 1 | export { ApiDataTypes as DataTypes } from '@scs/api';
| ^
2 |
Expected Behavior
Jest was working great with 14.1.6-beta.1
Environment
Node : 18.1.0
OS : darwin arm64
yarn : 1.22.17
nx : 14.1.7-beta.2
@nrwl/angular : 14.1.7-beta.2
@nrwl/cypress : 14.1.7-beta.2
@nrwl/detox : Not Found
@nrwl/devkit : 14.1.7-beta.2
@nrwl/eslint-plugin-nx : 14.1.7-beta.2
@nrwl/express : Not Found
@nrwl/jest : 14.1.7-beta.2
@nrwl/js : Not Found
@nrwl/linter : 14.1.7-beta.2
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/nx-cloud : 14.0.4-beta.1
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : 14.1.7-beta.2
@nrwl/web : Not Found
@nrwl/workspace : 14.1.7-beta.2
typescript : 4.6.4
rxjs : 7.5.5
---------------------------------------
Community plugins:
@ngrx/component-store: 13.2.0
@ngrx/data: 13.2.0
@ngrx/effects: 13.2.0
@ngrx/entity: 13.2.0
@ngrx/store: 13.2.0
@ngrx/store-devtools: 13.2.0
ng-mocks: 13.5.2
Also:
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"jest-preset-angular": "~12.1.0-next.0",
"ts-jest": "^28.0.2",
"ts-node": "^10.7.0",
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 17 (8 by maintainers)
Thanks a lot, will use it next time. Please consider adding an argument for “nx migrate” to set the “from”/“source” version, like
nx migrate --from=14.1.5 --to=latest
ornx migrate --source=14.1.5 --target=latest
For others: Root jest.config.ts should be:
Root jest.preset.ts:
In every app/lib jest.config.ts replace
module.exports = {
byexport default {
, as Colum mentioned.Thanks a lot for help, our tests are running again!!!
Same issue here! In my case it also throws an error in jest angular preset. I saw it first in v14.1.5
Cannot find module '@angular/core/testing' from '../../node_modules/jest-preset-angular/build/config/setup-jest.js'
https://github.com/ng-easy/platform/pull/500
Same issue:
nx 14.1.7
I did use
nx migrate
including the migration in@nrwl/jest
. Still seeing this errornx 14.1.7
Yup! Here https://github.com/ng-easy/renovate-config/blob/main/nrwlWorkspace.json
It is not super efficient, since Renovate processes tasks individually for every dependency. To sum up the way it works:
Anyway, it is a background task, so it will end up completing the upgrade in the background after a while. For me it has been working nicely! 🌈
nx migrate @nrwl/workspace@14.1.5 --from="@nrwl/workspace@14.1.4"
Nx migrate does support a
from
option 😃https://nx.dev/cli/migrate#from