Skip to content

Unhandled exception in handler 'index'. #12102

@Hawley-hy

Description

@Hawley-hy

Are you certain it's a bug?

  • Yes, it looks like a bug

Is the issue caused by a plugin?

  • It is not a plugin issue

Are you using the latest v3 release?

  • Yes, I'm using the latest v3 release

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Issue description

I use webpack build my project. the code as bellow that after build.

`// (() => { // webpackBootstrap
/
/ "use strict";

/!!
!
./index.ts !
*
*/

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.handler = void 0;
const lambda_1 = webpack_require(/*! ./src/lambda */ "./src/lambda.ts");
const handler = function (event, context, callback) {
console.log('123123123', lambda_1.handler);
(0, lambda_1.handler)(event, context, callback);
};
exports.handler = handler;

})();

/******/ })()
;
//# sourceMappingURL=index.js.map`

the error as bellow:

image

Service configuration (serverless.yml) content

service: serverless-nestjs
custom:
  serverless-offline:
    httpPort: 4000

provider:
  name: aws
  stage: ${opt:stage, 'dev'}
  runtime: nodejs16.x
  region: us-east-1

plugins:
  - serverless-offline

package:
  exclude:
    - .git/**
    - src/**
    - test/**
    - e2e/**
    - nodemon.json
    - README.md

functions:
  index:
    handler: dist/index.handler
    events:
      - http:
          cors: true
          path: '/'
          method: any
      - http:
          cors: true
          path: '{proxy+}'
          method: any
    environment:
      Encrypt_TokenUrl: ${file(./config.json):Encrypt_TokenUrl}
      Encrypt_ClientID: ${file(./config.json):Encrypt_ClientID}
      Encrypt_ClientSecret: ${file(./config.json):Encrypt_ClientSecret}
      Encrypt_GrantType: ${file(./config.json):Encrypt_GrantType}

Command name and used flags

sls offline start

Command output

Offline [http for lambda] listening on http://localhost:3002
Function names exposed for local invocation by aws-sdk:
           * index: serverless-nestjs-dev-index

   ┌─────────────────────────────────────────────────────────────────────────┐
   │                                                                         │
   │   ANY | http://localhost:4000/dev                                       │
   │   POST | http://localhost:4000/2015-03-31/functions/index/invocations   │
   │   ANY | http://localhost:4000/dev/{proxy*}                              │
   │   POST | http://localhost:4000/2015-03-31/functions/index/invocations   │
   │                                                                         │
   └─────────────────────────────────────────────────────────────────────────┘

Server ready: http://localhost:4000 🚀


ANY /dev (λ: index)
✖ Unhandled exception in handler 'index'.
✖ Runtime.HandlerNotFound: SERVERLESS_API/serverless-api/dist/index.handler is undefined or not exported


### Environment information

```shell
Framework Core: 3.34.0 (local)
Plugin: 6.2.3
SDK: 4.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions