Skip to content

@nx/jest resolves ts paths wrong #31351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 4 tasks
its-dibo opened this issue May 27, 2025 · 0 comments
Open
1 of 4 tasks

@nx/jest resolves ts paths wrong #31351

its-dibo opened this issue May 27, 2025 · 0 comments

Comments

@its-dibo
Copy link

Current Behavior

In my project's tsconfig.json and tsconfig.spec.json I specified alias paths

  "paths": {
      "~~*": ["../../*"], //<-- refers to the workspace's root
     // .... other paths
    }

in /jest.config.ts

import jestConfig from '~~jest.config';
export default jestConfig({ _projectRoot: __dirname });

When I add the plugin nx add @nx/jest, the following error occurs

5 errors occurred while processing files for the @nx/jest/plugin plugin
.
  - apps/assets/jest.config.ts: Cannot find module '../../~~jest.config'
Require stack:
- /workspaces/mashrouk/apps/assets/jest.config.ts
- /workspaces/mashrouk/node_modules/.pnpm/@[email protected][email protected]_@[email protected]_@[email protected]_@[email protected]__ffljwscjdaomkqev3az6ugtrei/node_modules/@nx/devkit/src/utils/config-utils.js
- /workspaces/mashrouk/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@swc+help_oj4j7lrynaepz4txa3cmv4ytzy/node_modules/@nx/jest/src/plugins/plugin.js
- /workspaces/mashrouk/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@swc+help_oj4j7lrynaepz4txa3cmv4ytzy/node_modules/@nx/jest/src/generators/init/init.js
- /workspaces/mashrouk/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_7t2fh5y3gx2kwbf7qy6cwswh3m/node_modules/nx/src/config/schema-utils.js
- /workspaces/mashrouk/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_7t2fh5y3gx2kwbf7qy6cwswh3m/node_modules/nx/src/command-line/run/executor-utils.js
- /workspaces/mashrouk/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_7t2fh5y3gx2kwbf7qy6cwswh3m/node_modules/nx/src/project-graph/utils/project-configuration-utils.js
- /workspaces/mashrouk/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_7t2fh5y3gx2kwbf7qy6cwswh3m/node_modules/nx/src/utils/package-json.js
- /workspaces/mashrouk/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_7t2fh5y3gx2kwbf7qy6cwswh3m/node_modules/nx/bin/nx.js
  - apps/core/jest.config.ts: Cannot find module '../../~~jest.config'
...

According to ts paths, the resolved path should be ../../jest.config instead of ../../~~jest.config

I can run the test without NX without any problem, and vs code can see the path correctly

Image

Expected Behavior

The alias path should be resolved correctly

GitHub Repo

No response

Steps to Reproduce

  1. add paths to the projects tsconfig.json and tsconfig.spec.json
  2. create jest.config.ts in the project's root
  3. use the alias path

Nx Report

Node           : 22.12.0
OS             : linux-x64
Native Target  : x86_64-linux
pnpm           : 9.15.0

nx (global)  : 21.1.2
nx           : 21.1.2
@nx/js       : 21.1.2
@nx/jest     : 21.1.2
@nx/eslint   : 21.1.2
typescript   : 5.8.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
---------------------------------------
Cache Usage: 7.76 MB / 46.73 GB

Failure Logs

Package Manager Version

pnpm v9.15.0

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant