Skip to content

[Bug]: "Cannot find module" with automocked Node.js builtin module and custom resolver in v30 #15676

@joshkel

Description

@joshkel

Version

30.0.0

Steps to reproduce

  1. Clone https://github.com/joshkel/jest-automock-custom-resolver
  2. npm i
  3. npm test

Expected behavior

Successful test completion

Actual behavior

 FAIL  ./test.ts
  ● Test suite failed to run

    Cannot find module 'node:child_process' from 'test.ts'

    > 1 | import { spawn } from 'node:child_process';
        | ^
      2 |
      3 | jest.mock('node:child_process');
      4 |

      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/index.js:868:11)
      at Object.<anonymous> (test.ts:1:1)

Additional context

From what I can tell, this bug only happens if the following are all true:

  • Mocking a built-in Node.js module
  • Using automock (i.e., not specifying a factory function)
  • Using a custom resolver (even if all that resolver does is call the default resolver)

Environment

System:
    OS: macOS 15.5
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 22.15.0 - ~/.nvm/versions/node/v22.15.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.15.0/bin/npm
    bun: 1.2.15 - /opt/homebrew/bin/bun
  npmPackages:
    jest: ^30.0.0 => 30.0.0

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