nodejs icon indicating copy to clipboard operation
nodejs copied to clipboard

chore: readme update for esm support to aws lambda

Open aryamohanan opened this issue 8 months ago • 0 comments

AWS Lambda provides support for ES modules with the introduction of Node.js v14. However, there are limitations regarding ES modules in layers, leading to two identified issues: the inability to import ES modules from layers and the inability to designate ES modules as handlers within layers. These challenges persist for Node.js versions 14 and 16, which are not in LTS (Long-Term Support).

To address these limitations, our ES handlers are currently using as CommonJS modules with dynamic imports.

The Node.js 18.x runtime introduces a solution by supporting ES module resolution using NODE_PATH, see Node.js 18.x runtime now available in AWS Lambda.

As mentioned in a comment on GitHub (source), the workaround involves upgrading to Node.js 18. As Node.js 14 and 16 are not in LTS, we can continue using the existing workaround(AWS not fixed issue in these versions). In the next major release(v4), we plan to drop support for Node.js 14 and 16, and fully transition to Node.js 18, which should resolve the issue. The Node.js 18.x runtime for Lambda searches the folders listed in NODE_PATH when loading ES modules. This makes it easier to include the AWS SDK as an ES module or load ES modules from Lambda layers.

aryamohanan avatar Jun 20 '24 13:06 aryamohanan