-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
Is there an existing issue for this?
- I have searched existing issues, it hasn't been reported yet
Use case description
Since AWS Lambda supports ES modules (#1, #2) that would be a great feature to support *.mjs
extensions.
The use case is as follows:
A repository uses JavaScript. Since ES modules gained support in early 2022 the code uses CommonJS as a system of imports. The steps to move away from CommonJS to native ES modules could be:
- add
"type": "commonjs"
topackage.json
- refactor functions one by one. All untouched functions are CommonJS so no changes are needed, the refactored ones are marked by
*.mjs
extension - after all functions are refactored
"type": "module"
inpackage.json
is used and all files previously having*.mjs
extension can have their extensions changed back to*.js
Currently the refactoring process would look a bit more cumbersome:
- since
*.mjs
is not supported one must set"type": "module"
inpackage.json
- files must be renamed to have
*.cjs
extension - after function is refactored its name can be changed back to
*.js
This may not look as a big issue at first since that's the same process just the other way around but it unnecessarily introduces changes to files that are in fact not refactored at the moment. This becomes clearly visible especially when there are shared modules that must have their extensions changed to *.cjs
and then all configuration files / imports must reflect this change even if they are not in scope of refactoring at the specific moment.
The reason for opening this issue is that according to this #11143 (comment) the implementation has been postponed but there is clearly a use case for that feature.