Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add support for ES Modules with esbuild. #426

Closed
santiperone opened this issue Jan 12, 2023 · 4 comments
Closed

Feature request: Add support for ES Modules with esbuild. #426

santiperone opened this issue Jan 12, 2023 · 4 comments
Labels
type/feature Feature request

Comments

@santiperone
Copy link

Describe your idea/feature/enhancement

Currently, when trying to use ES modules features (as described in https://aws.amazon.com/es/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/) together with esbuild, some errors are thrown because the default output format for esbuild is .cjs, which doesn't support those.

Proposal

Add some option to change the output format to .mjs (maybe it could even be the default value)

@santiperone santiperone added stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. type/feature Feature request labels Jan 12, 2023
@mildaniel
Copy link
Contributor

Hey @santiperone, thanks for reporting this. SAM-CLI should already be exposing the format property, though I see it missing from our documentation which we will fix.

Can you try using one of the supported esbuild formats as defined in their documentation and see if it works
https://esbuild.github.io/api/#format

@hnnasit hnnasit added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Jan 12, 2023
@santiperone
Copy link
Author

Hi @mildaniel Thanks fo your response. You're right, there's actually a "Format" property that allows to set the output format to "esm". However, the output file still has ".js" extension instead of ".mjs" which makes the lambda runtime treat it as commonJs and makes it impossible to run. Also, is there any way of setting some of the esbuild properties globally? It's kind of a pain having to set that up on every function.

@mildaniel
Copy link
Contributor

Hey @santiperone. I moved the issue to the Lambda Builders repository. This is our build engine that handles the relevant logic. I also opened a pull request to add support for the --out-extension flag which will allow you to specify .mjs as the file extensions by adding this snippet to your template.

BuildMethod: esbuild
BuildProperties:
    OutExtension: 
     - .js=.mjs

As for your configuration concern, it's one we've heard before and are actively working on.

@mildaniel mildaniel removed the blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. label Feb 1, 2023
@mildaniel
Copy link
Contributor

This has now been released in AWS-SAM-CLI version 1.72.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature Feature request
Projects
None yet
Development

No branches or pull requests

4 participants