Jest in Angular workspace can not find paths to libraries
See original GitHub issueAfter 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",
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:16 (5 by maintainers)
Top Results From Across the Web
Testing with Nx, Jest and Angular - Can't find library when ...
This works fine, The IDE is able to resolve the libraries and I can serve the application with ng serve . However when...
Read more >Migrate your Angular library to Jest | by Kevin Kreuzer - Medium
By default, the Angular CLI generates new Angular projects with Karma as a testing framework and Jasmine as an assertion library.
Read more >Integrate Jest into an Angular application and library
As we can see, it builds our library inside the dist folder. This is also the folder where the paths created by the...
Read more >nrwl-nx/community - Gitter
@FrozenPandaz or someone else, I'm struggling to switch a workspace with two libraries in it from Jest to Karma. I can't use Jest...
Read more >Angular >=13 | jest-preset-angular - GitHub Pages
With Jest 28 and jest-preset-angular v12.0.0, ng-jest-resolver is no longer ... Cannot find modules error when importing any deep paths from Angular ESM ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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