Skip to content

Add module-sync condition to default ssr.resolve.externalCondition #19201

Open
@sapphi-red

Description

@sapphi-red

Description

module-sync condition is a condition enabled by Node.js when require(esm) is enabled. It is supported by the config loader (#18650), but not by the SSR module loader.

Suggested solution

Add module-sync condition to default ssr.resolve.externalCondition.

Alternative

Leave it as-is and tell users to configure it when needed.

Additional context

  • related: Resolution allows extension-less import which is not aligned with package exports field #18300
  • we don't support export { foo as 'module.exports' } (module: support 'module.exports' interop export name in require(esm) nodejs/node#54563) in the config loader but we should support that as well
  • The reason of not proposing adding module-sync to ssr.resolve.conditions is to follow Node.js's recommendation.
    Quoting from the Node 22.10.0 release post:

    For bundlers/tools: they should avoid implementing this stop-gap condition. Most existing bundlers implement the de-facto bundler standard module exports condition, and that should be enough to support users who want to bundle ESM from CJS consumers. Users who want both bundlers and Node.js to recognize the ESM exports can use both module/module-sync conditions during the transition period, and can drop module-sync+module when they no longer need to support older versions of Node.js. If tools do want to support this condition, it's recommended to make the resolution rules in the graph pointed by this condition match the Node.js native ESM rules to avoid divergence.

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions