Closed ChetanUpreti99 closed 2 months ago
Thanks for you detailed report.
v5.x does not support CommonJS anymore due to the increasing complexities of maintaining it, but more importantly, ESM support within lambda is mature and gives a notable performance enhancement during cold starts.
Options:
a) Recommend to the Serverless Framework to upgrade their build process to use ESM and take advantage of these performance gains.
b) use Middy v4.x, it's really stable.
c) wait for Node 22 and use --experimental-require-module
(untested), use Middy 4.x in the mean time.
Bug Report: Incompatibility of
@middy/core
with Node.js v20.16.0 in Serverless Framework ProjectDescribe the Bug
When attempting to use
@middy/core
in an AWS Lambda handler with the following environment:I encountered the following error:
This error occurs consistently when the Lambda function is executed, both in a local environment using
serverless-offline
and when deployed to AWS.To Reproduce
Steps to reproduce the behavior:
Set up a simple Serverless Framework project using Node.js with the following handler configuration:
Run the function locally using
serverless-offline
or deploy the function to AWS and trigger it.Observe the following error message:
A minimal reproducible example is available in this GitHub repository: GitHub Repo Link.
Expected Behavior
The Lambda function should execute successfully without errors, with proper recognition and functionality of the
@middy/core
middleware.Environment
Additional Context
exports
field in the@middy/core
package'spackage.json
file. It seems that the module is not correctly exported or recognized in the current Node.js setup, possibly due to differences in module resolution or ES Module compatibility.Suggested Actions:
exports
field in thepackage.json
file of@middy/core
to ensure compatibility with both CommonJS and ES Module environments.@middy/core
in various module systems, especially when using the Serverless Framework.I can help you with more information or collaborate on testing potential fixes.