Skip to content

[Invoke local aws] Support for ES modules - *.mjs #11308

@krkcode60

Description

@krkcode60

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:

  1. add "type": "commonjs" to package.json
  2. refactor functions one by one. All untouched functions are CommonJS so no changes are needed, the refactored ones are marked by *.mjs extension
  3. after all functions are refactored "type": "module" in package.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:

  1. since *.mjs is not supported one must set "type": "module" in package.json
  2. files must be renamed to have *.cjs extension
  3. 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.

Proposed solution (optional)

PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions