Skip to content

module: deprecate "main" index and extension lookups

This adds a new deprecation warning when importing a main that resolves to an ES module that relies on the "index" or extension searching "main" resolution semantics.

In the next major this can become a runtime error, while for now it is behind --pending-deprecation only.

This is an update to the previous iteration which allows "main" and "exports" to continue to coexist without encapsulation being enforced.

The two warnings shown are for extensions not present:

Package /home/guybedford/Projects/node/test/fixtures/node_modules/default_index/ has a "main" field set to "index", excluding the full extension to the resolved file at "index.js", imported from /home/guybedford/Projects/node/test/fixtures/pkgexports.mjs.
 Automatic extension resolution of the "main" field is deprecated for ES modules.

and for no main field present:

No "main" or "exports" field defined in the package.json for /home/guybedford/Projects/node/test/fixtures/node_modules/no_exports/ resolving the main entry point "index.js", imported from /home/guybedford/Projects/node/test/fixtures/pkgexports.mjs.
Default "index" lookups for the main are deprecated for explicit definitions.

The warning is shown for third party packages and local packages equally.

This approach was taken after discussion that pushing encapsulation or deprecating the main would be too strong of a move to make.

Merge request reports

Loading