Skip to content

Reconsidering this proposal #6

Closed
@guybedford

Description

@guybedford

I really like the simplicity of this proposal... it could be really worthwhile to flesh it out again and work through some of the cases given current developments. For example how it might interplay with ".mjs" which looks like it may well be here to stay at this point.

Here's my best shot at this -

  • require.import is now provided by the dynamic import, so is effectively already implemented.
  • An ".mjs" package.json "main" or index.mjs would likely still need to be supported in lookups (at least to fit in with the current Node implementation). In addition "node x.mjs" would likely need to automatically enable the "--module" flag. Other than that, ".mjs" holds no further meaning.

I must say I do still have concerns over the idea that there is no "main" field for ES modules, and they must use a "default.js". Perhaps a "default" in the package.json could be considered here? I do really like that this is entirely optional though, that seems a very compelling feature of this proposal.

I don't see an issue with subpath requires being unavailable for ESM -> CJS boundaries, but perhaps the "looseness" of the definition of whether a given file is ESM or CJS is my greatest concern, which is avoided by the "mode" proposal (nodejs/node#18392).

The more I look at this, the more it seems like it makes the right tradeoffs overall to me though... it would be very interesting to prototype the approach and see how it feels in Node.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions