question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`nx test` (jest) cannot resolve tsconfig paths after migration to nx 14.x

See original GitHub issue

Current Behavior

After migrating to nx 14, all my tests that import modules from aliased paths (from my libs) fail. The app builds fine and VSCode shows no issues with the module resolution, but when running tests, jest is no longer able to resolve my path aliases:

image image

Expected Behavior

The tests should pass.

Steps to Reproduce

nx migrate latest on my main branch here:

https://github.com/hevans90/idleverse

Then nx test to run my default project’s testing suite with the failing tests.

OR, check out this branch and nx test:

https://github.com/hevans90/idleverse/tree/build/nx-14


This issue may not be prioritized if details are not provided to help us reproduce the issue.

Failure Logs

Environment

Node : 16.13.2 OS : darwin x64 yarn : 1.22.18

nx : 14.2.2 @nrwl/angular : Not Found @nrwl/cypress : 14.2.2 @nrwl/detox : Not Found @nrwl/devkit : 14.2.2 @nrwl/eslint-plugin-nx : 14.2.2 @nrwl/express : Not Found @nrwl/jest : 14.2.2 @nrwl/js : 14.2.2 @nrwl/linter : 14.2.2 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : 14.2.2 @nrwl/nx-cloud : 14.0.8 @nrwl/nx-plugin : Not Found @nrwl/react : 14.2.2 @nrwl/react-native : Not Found @nrwl/schematics : Not Found @nrwl/storybook : 14.2.2 @nrwl/web : 14.2.2 @nrwl/workspace : 14.2.2 typescript : 4.7.3

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
barbados-clemenscommented, Jun 10, 2022

@jonwalstedt thanks for the diff, it looks like it was when I changed the nxPreset. Looking at your root jest.preset.js it doesn’t have the updated version @hevans90

You’ll want to add .default to the nxPreset import.

- const nxPreset = require('@nrwl/jest/preset');
+ const nxPreset = require('@nrwl/jest/preset').default;

module.exports = { ...nxPreset };

This should have been fixed in v14.1.5 migration for you. You can try rerunning that migration to see if it’s added as you’re preset is the default so there isn’t a reason it shouldn’t work. Or just manually make that change. This was causing the @nrwl/jest/plugins/resolver to not resolve the module names.

2reactions
jcabannescommented, Sep 19, 2022

Hello @barbados-clemens , I work with @christophechevalier . I didn’t succeed to make a Stackblitz project reproducing the error, so I created a small project on github, available at this address. If you have any questions or problems do not hesitate to contact us.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NX workspace - angular 14 - jest not working - Stack Overflow
As of today (like just now...) I was able to upgrade to 14. nx migrate latest. Open the root package.json file.
Read more >
Migrating an Angular CLI project to Nx
This command will install the correct version of Nx based on your Angular version. This will enable you to use the Nx CLI...
Read more >
Configuring Jest
For example, with the following configuration: JavaScript; TypeScript. /** @type {import('jest').Config} */
Read more >
Nx/community - nrwl - Gitter
TS2307: Cannot find module '@w/components/app-bar' or its corresponding type declarations. ... For anyone using Angular and unit-testing it with Jest:
Read more >
Cannot find module '@angular/core' error | bobbyhadz
To solve the error "Cannot find module '@angular/core'", make sure you have installed all dependencies by running the npm install command, set the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found