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

[Bug]: Does not work with AWS Lambda with TopLevelAwait enabled (ESM) #7146

Closed
cjnoname opened this issue Jul 14, 2024 · 0 comments · Fixed by #7308
Closed

[Bug]: Does not work with AWS Lambda with TopLevelAwait enabled (ESM) #7146

cjnoname opened this issue Jul 14, 2024 · 0 comments · Fixed by #7308
Labels
bug Something isn't working pending triage The issue/PR is currently untouched.

Comments

@cjnoname
Copy link

System Info

System:
OS: macOS 14.5
CPU: (10) arm64 Apple M1 Max
Memory: 1.97 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
npm: 10.8.1 - ~/.nvm/versions/node/v20.14.0/bin/npm
Browsers:
Chrome: 126.0.6478.127
Safari: 17.5
npmPackages:
@rspack/cli: 1.0.0-alpha.3 => 1.0.0-alpha.3
@rspack/core: 1.0.0-alpha.3 => 1.0.0-alpha.3

Details

When using AWS Lambda, there must be a function exported called "handler".

Normally, we can export the handler function without any issues.

However, with "TopLevelAwait" enabled, the bundled file does not work with AWS Lambda. This is because the "handler" function is exported as y = n ? Symbol.for("@reflect-metadata:registry") : void 0, which is not a regular function and therefore won't be recognized by AWS Lambda.

To be completely fair, ESModules natively support top-level await, which means we don't need to do extra work to build a separate implementation for it. Nonetheless, please help find a way to solve this issue.

Thanks,
CJ

Reproduce link

https://github.com/cjnoname/example-esm-lambda

Reproduce Steps

In the "lambda.ts" file:

When the line console.log(await bb()); is commented out, the handler function can be exported correctly in the build file, and it works properly on AWS Lambda.

However, when the line console.log(await bb()); is enabled, the handler function is built as y = n ? Symbol.for("@reflect-metadata:registry") : void 0, which is not a regular function and therefore won't be recognized by AWS Lambda.

Please run the npm build script to regenerate the file.

@cjnoname cjnoname added bug Something isn't working pending triage The issue/PR is currently untouched. labels Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage The issue/PR is currently untouched.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant