Skip to content

require.cache entries missing children for dynamically imported CommonJS TypeScript files #61385

@zachleat

Description

@zachleat

Version

v24.13.0

Platform

25.1.0 Darwin Kernel Version 25.1.0: Mon Oct 20 19:33:36 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6030 arm64

Subsystem

No response

What steps will reproduce the bug?

// index.js (CommonJS)
(async () => {
  await import("./target.ts");
  console.log(require.cache);
})();

where target.ts contains:

// target.ts (CommonJS)
require("./deps/child.ts");
require("./deps/child.js");

Running node index.js shows an empty array for children: [] when it should be populated with 2 entries.

Notably, import() does add an entry to require.cache for target.ts (and a hypothetical target.js) but only the TypeScript version is missing the correct value for children.

Workaround: use require for CommonJS TypeScript instead of dynamic import.

How often does it reproduce? Is there a required condition?

100% consistent every time

What is the expected behavior? Why is that the expected behavior?

I would expect the children Array to have two entries for the require()’d dependencies.

What do you see instead?

children: [] (empty Array)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions