middyjs / middy

🛵 The stylish Node.js middleware engine for AWS Lambda 🛵
https://middy.js.org
MIT License
3.7k stars 374 forks source link

Bug Report: Incompatibility of `@middy/core` with Node.js v20.16.0 in Serverless Framework Project #1231

Closed ChetanUpreti99 closed 1 month ago

ChetanUpreti99 commented 1 month ago

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:

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:

  1. Set up a simple Serverless Framework project using Node.js with the following handler configuration:

    import middy from '@middy/core';
    
    export const Signup = middy(async function (_event, _context) {
        return {
            statusCode: 200,
            body: JSON.stringify({
                message: 'Hello world'
            })
        };
    });
  2. Run the function locally using serverless-offline or deploy the function to AWS and trigger it.

  3. 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

Additional Context

Suggested Actions

  1. Review and update the exports field in the package.json file of @middy/core to ensure compatibility with both CommonJS and ES Module environments.
  2. 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.

willfarrell commented 1 month ago

Duplicate of #1230