CodeGenieApp / serverless-express

Run Express and other Node.js frameworks on AWS Serverless technologies such as Lambda, API Gateway, Lambda@Edge, and more.
https://codegenie.codes
Apache License 2.0
5.18k stars 672 forks source link

TypeError: Cannot read property 'callback' of undefined #485

Open jeff-pal opened 2 years ago

jeff-pal commented 2 years ago
const { getCurrentInvoke } = require('@vendia/serverless-express')
app.get('/', (req, res) => {
  const { event, context } = getCurrentInvoke()

  res.json(event)
})

What is wrong about the code above? I'm getting the following error:

TypeError: Cannot read property 'callback' of undefined
    at getFramework (/my-app/node_modules/@vendia/serverless-express/src/frameworks/index.js:7:18)
    at configure (/my-app/node_modules/@vendia/serverless-express/src/configure.js:22:35)
    at ResizeToThreeDimensionsController.handle (/my-app/src/adapters/resizeToThreeDimensionsController.ts:81:40)
    at Layer.handle [as handle_request] (/my-app/node_modules/express/lib/router/layer.js:95:5)
    at next (/my-app/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/my-app/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/my-app/node_modules/express/lib/router/layer.js:95:5)
    at /my-app/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/my-app/node_modules/express/lib/router/index.js:341:12)
    at next (/my-app/node_modules/express/lib/router/index.js:275:10)
wildtangent commented 2 years ago

I am also getting this with a basic Express app (v4.17.1) + "@vendia/serverless-express": "^4.5.2",

server.js

const express = require('express');
const app = express();

// app setup

module.exports = app;

handler.js

const serverlessExpress = require('@vendia/serverless-express')
const server = require('./server');

module.exports = serverlessExpress({ server });

While running test suite


    at getFramework (/my-app/node_modules/@vendia/serverless-express/src/frameworks/index.js:7:18)
    at configure (/my-app/node_modules/@vendia/serverless-express/src/configure.js:22:35)
    at Object.<anonymous> (/my-app/src/handler.js:7:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/my-app/test/integration/handler.test.js:4:17)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
    at async Loader.import (internal/modules/esm/loader.js:178:24)
    at async formattedImport (/my-app/node_modules/mocha/lib/nodejs/esm-utils.js:7:14)
    at async Object.exports.requireOrImport (/my-app/node_modules/mocha/lib/nodejs/esm-utils.js:48:32)
    at async Object.exports.loadFilesAsync (/my-app/node_modules/mocha/lib/nodejs/esm-utils.js:88:20)
    at async singleRun (/my-app/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at async Object.exports.handler (/my-app/node_modules/mocha/lib/cli/run.js:374:5)```
binggaofw commented 2 years ago

see the same issue "@vendia/serverless-express": "~4.8.0" + "express": "4.17.3", index.js


const { app } = require('./server/app');
const serverlessExpress = require('@vendia/serverless-express');
/**
 * Main entry point for the application
 */
 exports.handler =  serverlessExpress({ app} );

was lambda error { "errorType": "TypeError", "errorMessage": "Cannot read property 'callback' of undefined", "stack": [ "TypeError: Cannot read property 'callback' of undefined", " at getFramework (/var/task/node_modules/@vendia/serverless-express/src/frameworks/index.js:7:18)", " at configure (/var/task/node_modules/@vendia/serverless-express/src/configure.js:22:35)", " at Object.<anonymous> (/var/task/index.js:10:21)", " at Module._compile (internal/modules/cjs/loader.js:1085:14)", " at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)", " at Module.load (internal/modules/cjs/loader.js:950:32)", " at Function.Module._load (internal/modules/cjs/loader.js:790:12)", " at Module.require (internal/modules/cjs/loader.js:974:19)", " at require (internal/modules/cjs/helpers.js:101:18)", " at _tryRequireFile (/var/runtime/UserFunction.js:63:32)" ] }

paulorgl commented 2 years ago

same error in here

const serverlessExpress = require('@vendia/serverless-express');
const app = require('./serverless/main').server;
exports.handler = serverlessExpress({ app })

version: "@vendia/serverless-express": "4.8.0"

Graeme43 commented 2 years ago

Change the handler.js to the following.

exports.handler = serverlessExpress({ app: app })