Skip to content

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

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

Activity

  1. zachleat commented on Jan 14, 2026

    @zachleat
    Author

    Cross-link to marginally related #59868

  2. backflip commented on Jan 15, 2026

    @backflip

    Cross-link to marginally related #59868

    @zachleat The linked issue is referenced from #59874 which seems to explain the behavior you are experiencing unless I'm missing something.

    Specifically: https://github.com/nodejs/node/pull/59874/files#diff-1b1ae477505d4d28dcbc36f9983381a62ee28ffa354dc85ad008ffa8c764cabeR8

    Image

    UPDATE: Sorry for the spam, probably confusing ESM and CommonJS here.

  3. zachleat commented on Jan 16, 2026

    @zachleat
    Author

    @backflip it was a good thought! But yeah the target TypeScript file is CommonJS there

  4. github-actions commented on Jul 20, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 90 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  5. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 20, 2026
  6. zachleat commented on Jul 20, 2026

    @zachleat
    Author

    I did retest and this appears to be fixed with v26.5.0 (2 children, fixed):

    '/Users/zachleatherman/Temp/node-issue-61385/target.ts': {
        id: '/Users/zachleatherman/Temp/node-issue-61385/target.ts',
        path: '/Users/zachleatherman/Temp/node-issue-61385',
        exports: {},
        filename: '/Users/zachleatherman/Temp/node-issue-61385/target.ts',
        loaded: true,
        children: [ [Object], [Object] ],
        paths: [
          '/Users/zachleatherman/Temp/node-issue-61385/node_modules',
          '/Users/zachleatherman/Temp/node_modules',
          '/Users/zachleatherman/node_modules',
          '/Users/node_modules',
          '/node_modules'
        ],
        Symbol(kIsCachedByESMLoader): true,
        Symbol(kFormat): 'commonjs-typescript',
        Symbol(kURL): 'file:///Users/zachleatherman/Temp/node-issue-61385/target.ts',
        Symbol(kIsExecuting): false
      },
    

    v24.18.0 (empty children, broken):

    '/Users/zachleatherman/Temp/node-issue-61385/target.ts': {
        id: '/Users/zachleatherman/Temp/node-issue-61385/target.ts',
        path: '/Users/zachleatherman/Temp/node-issue-61385',
        exports: {},
        filename: '/Users/zachleatherman/Temp/node-issue-61385/target.ts',
        loaded: true,
        children: [],
        paths: [
          '/Users/zachleatherman/Temp/node-issue-61385/node_modules',
          '/Users/zachleatherman/Temp/node_modules',
          '/Users/zachleatherman/node_modules',
          '/Users/node_modules',
          '/node_modules'
        ],
        Symbol(kIsCachedByESMLoader): true
      },
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions