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.17k stars 671 forks source link

Runtime.HandlerNotFound with serverlessExpress({ app }) #370

Closed 486 closed 3 years ago

486 commented 3 years ago

Hi,

The examples, e.g. basic-starter-api-gateway-v1 suggest to use code like

require('source-map-support/register')
const serverlessExpress = require('@vendia/serverless-express')
const app = require('./app')

exports.handler = serverlessExpress({ app })

But that doesn't work for me (I followed the guide for basic-starter-api-gateway-v1) - the Lambda invocation fails with

2021-02-12T08:22:17.961Z    undefined   ERROR   Uncaught Exception  
{
    "errorType": "Runtime.HandlerNotFound",
    "errorMessage": "main.handler is not a function",
    "stack": [
        "Runtime.HandlerNotFound: main.handler is not a function",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:150:11)",
        "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
        "    at Module._compile (internal/modules/cjs/loader.js:999:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
        "    at Module.load (internal/modules/cjs/loader.js:863:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
        "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
        "    at internal/main/run_main_module.js:17:47"
    ]
}

Looking at the return value of serverlessExpress(), it is an object where the handler is one of its keys. Thus, it works for me when changing the export to

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

Am I missing something here? Because I haven't seen this in any example.

brettstack commented 3 years ago

Fixed. I forgot to run npm update in the examples to use the latest version of this package. You can either git pull the latest, or run npm update within the example directory you're using.