Top Level Await - Serverless Framework with Esbuild plugin

Does anyone know a way to have top-level await inside a lambda (Node) function using the serverless framework with esbuild?

What has been tried:

  • Setting “type”:“module” in package.json
    Error: Top-level await is currently not supported with the “cjs” output format (understandable as cjs modules cannot have top level awaits
  • Next tried setting esbuild platform: “neutral” (esm support)
    Error: No longer has access to node modules

What is the correct configuration to allow esm support, allowing for top level await?

3 Likes

Also experiencing this issue, did you find a solution?