Bug Report: Incompatibility of @middy/core with Node.js v20.16.0 in Serverless Framework Project
Describe the Bug
When attempting to use @middy/core in an AWS Lambda handler with the following environment:
Node.js Version: v20.16.0
Middy Version: 5.3.3
Serverless Framework Version: 4.1.20
I encountered the following error:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/chetanupreti/Desktop/SELF_PROJECT/NODEJS/nodejs-serverless-learnings/user-service2/node_modules/@middy/core/package.json
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:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /path/to/node_modules/@middy/core/package.json
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
Node.js Version: v20.16.0
Middy Version: 5.3.3
Serverless Framework Version: 4.1.20
Operating System: macOS Sonoma 14.5
Additional Context
The issue appears to be linked to the exports field in the @middy/core package's package.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.
The problem occurs consistently in local and deployed environments, suggesting that it may relate to how the module is packaged or consumed.
Suggested Actions
Review and update the exports field in the package.json file of @middy/core to ensure compatibility with both CommonJS and ES Module environments.
Provide clear documentation on how to properly import and use @middy/core in various module systems, especially when using the Serverless Framework.
I am available to provide further information or collaborate on testing potential fixes.
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 am available to provide further information or collaborate on testing potential fixes.