Skip to content

ESM re-exports from CJS module not included in exports #61989

Open

Description

@dsherret

Version

node-v

Platform

Microsoft Windows NT 10.0.26100.0 x64

Subsystem

No response

What steps will reproduce the bug?

// main.mjs
import * as mod from "./mod.js";
console.log(mod);

// mod.js
module.exports = {
  ...require("./other.js")
};

// other.js
export function test() {}
> node main.mjs  
[Module: null prototype] {
  default: { test: [Function: test] },
  'module.exports': { test: [Function: test] }
}
> deno -A --unstable-detect-cjs main.mjs
[Module: null prototype] {
  default: { test: [Function: test] },
  "module.exports": { test: [Function: test] },
  test: [Function: test]
}

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

Every time.

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

It should detect the "test" export from the ES module.

What do you see instead?

It's missing.

Additional information

No response

Activity

  1. Renegade334 commented on Feb 25, 2026

    @Renegade334
    Member

    To clarify, the request is for the import * CJS lexer to detect and parse ...require(esm) re-exports? Are there examples of this in the wild?

  2. dsherret commented on Feb 25, 2026

    @dsherret
    Author

    To clarify, the request is for the import * CJS lexer to detect and parse ...require(esm) re-exports?

    Yes. It currently doesn't handle it.

    Merve says if the file is ESM, so it would be possible to just run a pass on the file to get the ESM exports. That said, it would be even better if merve returned this information because then it would still be a single lexer pass.

    Are there examples of this in the wild?

    I don't have a specific example, but it's inevitable people will run into this during the transition to ESM (ex. one package re-exporting another package) and making this work properly will make that a smoother transition.

  3. alexsch01 commented on Feb 26, 2026

    @alexsch01
    Contributor

    I also notice this behavior with nodejs

    // main.mjs
    import * as mod from "./mod.js";
    console.log(mod);
    
    // mod.js
    module.exports = {
      test1() {},
      test2: () => {},
      foo: 'bar',
    };

    Output, test2 and foo are missing

    [Module: null prototype] {
      default: { test1: [Function: test1], test2: [Function: test2], foo: 'bar' },
      'module.exports': { test1: [Function: test1], test2: [Function: test2], foo: 'bar' },
      test1: [Function: test1]
    }

    in both my example and the OP's example

    changing

    import * as mod from "./mod.js";

    to

    import mod from "./mod.js";

    makes it less of an issue in nodejs

  4. dsherret commented on Feb 26, 2026

    @dsherret
    Author

    @alexsch01 that's a different issue with some property assignments in object literals not being recognized. nodejs/merve#27

    If I change other.js in the original issue from ESM (export function test() {}) to CJS (module.exports.test = 5;) it will work.

  5. 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.

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

    @dsherret
    Author

    Stale bots are one of the worst things. I will now participate in the ceremony of doing a comment to undo the stale label.

  8. removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 21, 2026
  9. github-actions commented on Oct 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.

  10. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Oct 20, 2026
  11. alexsch01 commented on Oct 20, 2026

    @alexsch01
    Contributor

    Keep open

  12. removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Oct 21, 2026
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

    loadersIssues and PRs related to ES module loaders.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions