dherault / serverless-offline

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

Unhandled exception in handler 'index'. #1719

Open Hawley-hy opened 1 year ago

Hawley-hy commented 1 year ago

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:

package: exclude:

functions: index: handler: dist/index.handler events:

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


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
Hawley-hy commented 1 year ago

my webpack module.exports = { devtool: process.env.NODE_ENV !== 'production' ? 'source-map' : 'none', mode: process.env.NODE_ENV, entry: { lambda: './src/lambda.ts', statup: './src/main.ts', index: './index.ts', }