Skip to content

More aggressive require(esm) #60108

@mtharrison

Description

@mtharrison

What is the problem this feature will solve?

Currently if you require(esm) from a CJS module it will only load conditionals in esm package exports: require, node, node-addons, module-sync. So if you e.g. const { delay } = require("unicorn-magic"); this will not work because exports from that package are:

{
  "node": {
    "types": "./node.d.ts",
    "import": "./node.js"
  },
  "default": {
    "types": "./default.d.ts",
    "import": "./default.js"
  }
}

The package wasn't designed with require(esm) in mind however it does work if you copy require conditions to be the same as the import conditions here.

What is the feature you are proposing to solve the problem?

For packages like the one in the example below could we also test import branches as in many case the module will load fine.

What alternatives have you considered?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions