dherault / dherault/serverless-offline

Unhandled exception in handler 'index'.

Open
#1,719 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.3k
Forks
811
Avg merge
2d 4h
Merged PRs (30d)
3

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`

`
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}
`
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

when I use webpack to bundle and build my project. the `sls offline start` not working well.

ANY /dev (λ: index)
✖ Unhandled exception in handler 'index'.

Though debug I fund `_tryRequire` can't load the js file that bundle by webpack

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.