dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.2k stars 794 forks source link

TypeError: ee.on is not a function #1832

Open Stankman opened 6 days ago

Stankman commented 6 days ago

Bug Report

Current Behavior

When running sls offline for a Serverless application using serverless-offline with the configuration below, an error occurs: TypeError: ee.on is not a function. This seems to prevent the expected startup of the local server.

Sample Code

service: sls-test

provider:
  name: aws
  runtime: nodejs20.x

functions:
  api:
    handler: dist/lambda.handler
    events:
      - http:
          path: /
          method: ANY
      - http:
          path: '{proxy+}'
          method: ANY

package:
  exclude:
    - node_modules/**

plugins:
  - serverless-offline
import serverlessExpress from '@codegenie/serverless-express';
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { Callback, Context, Handler } from 'aws-lambda';

let server : Handler;

export const handler = async (event: any, context: Context, callback: Callback) => {
    if(!server) {
        const app = await NestFactory.create(AppModule);
        await app.init();

        const expressApp = app.getHttpAdapter().getInstance();
        server = serverlessExpress({
            app: expressApp
        });
    }

    return server(event, context, callback);
}

Expected behavior/code

The application should start without errors and expose the API endpoints locally using serverless-offline.

Environment

optional, if you are using any of the following frameworks to invoke handlers

Possible Solution

It could be helpful to check for compatibility issues with serverless-offline or dependencies like ee-first in conjunction with the current node.js version.

Additional context/Screenshots

Output when running sls offline:

[Error Logs...]
✖ TypeError: ee.on is not a function
...
lAndresul commented 5 days ago

Same issue here

MehtaManan07 commented 2 days ago

Same issue happening for me as well, did anyone find a solution??

DorianMazur commented 12 hours ago

Hi @Stankman ! Can you post full error with the stacktrace?

DanielMaranhao commented 8 hours ago

Hi, I'm facing a similar issue, I believe it is mostly similar to the issue of Stankman. It occurs when trying to access http://localhost:3000/dev. In my case, the stack trace would be the following, but please feel free to post yours if it differs somehow.

TypeError: ee.on is not a function
    at first (C:\Workspaces\ws-nest\serverless-project\node_modules\ee-first\index.js:43:10)
    at onSocket (C:\Workspaces\ws-nest\serverless-project\node_modules\on-finished\index.js:115:16)
    at attachFinishedListener (C:\Workspaces\ws-nest\serverless-project\node_modules\on-finished\index.js:120:5)
    at attachListener (C:\Workspaces\ws-nest\serverless-project\node_modules\on-finished\index.js:147:5)
    at onFinished (C:\Workspaces\ws-nest\serverless-project\node_modules\on-finished\index.js:53:3)
    at send (C:\Workspaces\ws-nest\serverless-project\node_modules\finalhandler\index.js:319:3)
    at C:\Workspaces\ws-nest\serverless-project\node_modules\finalhandler\index.js:135:5
    at C:\Workspaces\ws-nest\serverless-project\node_modules\express\lib\router\index.js:646:15
    at next (C:\Workspaces\ws-nest\serverless-project\node_modules\express\lib\router\index.js:216:14)
    at Function.handle (C:\Workspaces\ws-nest\serverless-project\node_modules\express\lib\router\index.js:175:3)