-
Notifications
You must be signed in to change notification settings - Fork 4k
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
(lambdanodejs): using top level await fails at runtime #21329
Comments
if works perfectly when defined as simple Lambda function and not using crappy NodejsFunction this sample works perfectly
|
Workaround ('mainFields' is required to bundle ESM version of AWS SDK):
Why?Looks like it's not CDK / SDK, it somewhere between esbuild & uuid: uuid already has esm version in 'dist/node_esm', but per my (and issue author) stack trace we see that 'dist/rng.js' used instead. It's a bit complicated 'exports' field in uuid's package.json:
ESBuild shall choose exports->node->module instead of exports->node->import (which is proper way from my understanding). Yep, simple lambda with format: ESM
produces output with CJS version of uuid
From esbuild logs
With '--conditions=module' it works fine
Final thoughts: root cause is uuid package with strange exports section (see https://nodejs.org/api/packages.html#conditional-exports and try to find 'module' condition...) and mixed CJS / ESM ecosystem complexity. |
@koshic Your solution actually worked, thanks a lot! |
Describe the bug
Top level awaits cannot be used or fails at runtime always
Top level awaits are supported now in NodeJS lambda, however trying to deploy such a function with cdk contruct NodejsFunction always fails
here is the sample lambda function :
here is the definition with cdk
it fails with the following error always when trying to use top level awaits
if the bundling is not specified , the function cannot be even deployed
Expected Behavior
The function should execute normally and the output should be .js and not .mjs
Current Behavior
an .mjs file is generated and the execution always fails with
Reproduction Steps
create a function which uses top level await and deploy it using NodejsFunction
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.30.0
Framework Version
No response
Node.js Version
16
OS
Linux
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: