This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
Update esm/import to allow loading ESM from .js #847
Closed
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.
Motivation
In Node 12 it is possible to load ESM code from
.js
files as long as the closest package.json file has the property "type" set to "module". Currentlyesm
is failing withERR_INVALID_ESM_FILE_EXTENSION
. This can be easily reproduced by executing:Changes
Currently
esm
supports loading ESM code from a.js
file as long as the file that is importing the code is also.js
. This made me think thatERR_INVALID_ESM_FILE_EXTENSION
was only a restriction to be as close to Node 11.x modules implementation as possible.Following that naive logic I have just removed the check. If this is a desired feature but has deeper implications I am willing to further develop it with some guidance.