Skip to content

[Bug]: pathsToModuleNameMapper does not work correctly with tsconfig.json references #4702

@Woodz

Description

@Woodz

Version

29.1.5

Steps to reproduce

  1. Clone repo https://github.com/Woodz/tsconfigReferences_with_pathAliases
  2. Run yarn install
  3. Run yarn test

Expected behavior

I expect the test to pass

Actual behavior

Test fails with error:

    ../bar/src/bar.ts:1:10 - error TS2305: Module '"@common/util"' has no exported member 'convertBoolToString'.

    1 import { convertBoolToString } from '@common/util';

This is because ts-jest is mapping @common to foo/src/common even though the import is inside bar/src/bar.ts, which means that the mapping for @common should be to bar/src/common

Debug log

Not providing by default as it may contain sensitive information. Please request if needed

Additional context

Workaround is to use a custom Jest resolver as per #1648 (comment)

Environment

System:
    OS: macOS 15.1
    CPU: (8) arm64 Apple M2
  Binaries:
    Node: 22.13.0 - ~/.nvm/versions/node/v22.13.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.13.0/bin/npm
  npmPackages:
    jest: 29.7.0 => 29.7.0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions