serverless-express icon indicating copy to clipboard operation
serverless-express copied to clipboard

Bug Report: ee.on is not a function Error with @codegenie/serverless-express 4.16.0

Open rockyhuber opened this issue 6 months ago • 7 comments

Environment:

  • @codegenie/serverless-express: 4.16.0 (error occurs) / 4.15.0 (works)
  • Express: 4.19.2
  • Node.js: 20.x (AWS Lambda runtime)
  • TypeScript: 5.7.3

Error Description:

When using @codegenie/serverless-express version 4.16.0, the following error occurs consistently in AWS Lambda:

TypeError: ee.on is not a function
    at first (/var/task/node_modules/ee-first/index.js:43:10)
    at onSocket (/var/task/node_modules/on-finished/index.js:115:16)
    at attachFinishedListener (/var/task/node_modules/on-finished/index.js:120:5)
    at attachListener (/var/task/node_modules/on-finished/index.js:147:5)
    at onFinished (/var/task/node_modules/on-finished/index.js:53:3)
    at send (/var/task/node_modules/finalhandler/index.js:314:3)
    at /var/task/node_modules/finalhandler/index.js:133:5
    at /var/task/node_modules/express/lib/router/index.js:646:15
    at next (/var/task/node_modules/express/lib/router/index.js:265:14)
    at urlencodedParser (/var/task/node_modules/body-parser/lib/types/urlencoded.js:91:7)

Root Cause:

The error appears to be introduced in version 4.16.0 of @codegenie/serverless-express. The ee-first library expects an EventEmitter-like object but receives something that doesn't have the .on() method, suggesting a regression in how response objects are handled in the Lambda environment.

Reproduction Steps:

  1. Create a Lambda function with @codegenie/serverless-express 4.16.0
  2. Set up basic Express routes
  3. Deploy to AWS Lambda
  4. Make any HTTP request to the Lambda function

Workaround/Solution:

Downgrade to the previous working version:

{
  "@codegenie/serverless-express": "^4.15.0"
}

Code Pattern That Triggers Error:

import express from 'express';
import serverlessExpress from '@codegenie/serverless-express';

const app = express();
app.get('/health', (req, res) => res.send('ok'));

// This pattern causes the error with version 4.16.0
const serverlessHandler = serverlessExpress({ app });

export const handler = async (event, context) => {
    return serverlessHandler(event, context, () => {});
};

Expected Behavior:

The serverless handler should process requests without throwing ee.on is not a function errors.

Actual Behavior:

The error occurs during response processing, specifically when Express tries to attach event listeners for response completion tracking.

Additional Context:

  • The error only occurs in AWS Lambda environment, not in local development
  • The error happens after successful initialization but during request processing
  • Downgrading to 4.15.0 completely resolves the issue
  • This suggests a regression introduced in version 4.16.0

Version Comparison:

  • 4.15.0: ✅ Works correctly
  • 4.16.0: ❌ Throws ee.on is not a function error

Suggested Investigation:

Please review changes made between versions 4.15.0 and 4.16.0, particularly around response object handling and event emitter interactions in the Lambda environment.

rockyhuber avatar Jun 19 '25 02:06 rockyhuber

Experiencing the same issue

linokriza avatar Jul 30 '25 13:07 linokriza

same here on 4.16.0

alex-all3dp avatar Aug 27 '25 15:08 alex-all3dp

Any updates on this issue?

linokriza avatar Sep 18 '25 07:09 linokriza

I just downgraded to 4.15, and don't update.

rockyhuber avatar Sep 18 '25 09:09 rockyhuber

It's a huge hassle to downgrade because we migrated to express 5 with the release of v4.16.0 but I guess we have no other option.

linokriza avatar Sep 19 '25 13:09 linokriza

Weird because 4.16.0 has been out for almost a year. Did this only recently start happening? Does it happen in Express v5 also? Happy to merge PRs if anyone has a fix.

brettstack avatar Sep 20 '25 06:09 brettstack

To my knowledge this happens only on express 5

linokriza avatar Sep 24 '25 12:09 linokriza