Skip to content

[Bug]: Jest with TypeScript, ES modules and bundler moduleResolution cannot find additional modules #15607

Open
@ahtokca

Description

@ahtokca

Version

29.7.0 / 30.0.0-alpha.7

Steps to reproduce

  1. clone my repo at https://github.com/ahtokca/jest-module-not-found
  2. pnpm i
  3. jest
  4. you should see the error come up

Expected behavior

I expect the jest resolves the module and test passes as tsx --tsconfig tsconfig.json src/sub-entry.ts does

Actual behavior

Jest throws the error below:

Cannot find module 'custom-dependency/sub-entry' from 'src/sub-entry.spec.ts'

at Resolver._throwModNotFoundError (node_modules/.pnpm/[email protected]/node_modules/jest-resolve/build/resolver.js:427:11)
at Object.<anonymous> (src/sub-entry.spec.ts:4:34)

Additional context

Jest is not able to resolve the module path correctly when using "bundler" as the
module resolution strategy. It seems jest relies on naming convention "module-name.{d.ts|js}", so if module has a custom
naming in exports then jest tests will fail to discover the module.

Environment

System:
    OS: macOS 15.4.1
    CPU: (12) arm64 Apple M3 Pro
  Binaries:
    Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.17.0/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
    pnpm: 10.11.0 - ~/.nvm/versions/node/v20.17.0/bin/pnpm
    bun: 1.2.2 - ~/.nvm/versions/node/v20.17.0/bin/bun
  npmPackages:
    jest: 30.0.0-alpha.7 => 30.0.0-alpha.7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions