Support the "module" field of package.json for client code. #10541
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Like Node.js, Meteor's module system currently pays attention only to the
"main"
field ofpackage.json
files (and also"browser"
on the client) when resolving package entry points. This behavior effectively limits Meteor to using the CommonJS version of any npm packages, even though many packages have both a CommonJS and an ECMAScript module (ESM) entry point.This PR enables support for the
"module"
field for client code. The implementation required a few small adjustments: in particular, we now compile.js
files withinnode_modules
if they are contained by a package that has a"module"
entry point (only if theImportScanner
decides the module is actually used), and our module resolution logic now prefers the"module"
entry point both during build (resover.js
) and at runtime (modules-runtime
).Why is this important? Supporting ESM syntax everywhere is the future of JavaScript, first and foremost. Also, wherever ESM syntax is used, it's important for Meteor to have a chance to compile it, since we have an advanced module compiler called Reify.
Supporting
"module"
inpackage.json
for server code is not advisable because Node.js will be adopting the"type": "module"
convention instead, and in the meantime we need to maintain consistency with Node's module resolution rules, which only currently pay attention to"main"
.