Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Using serverless/koa with serverless V4.1.11 #302

Open
fvisticot opened this issue Jul 6, 2024 · 0 comments
Open

Error Using serverless/koa with serverless V4.1.11 #302

fvisticot opened this issue Jul 6, 2024 · 0 comments

Comments

@fvisticot
Copy link

Following the error and code trying to use Koa.
For information it works when using Express

Error:

ERROR Uncaught Exception {"errorType":"TypeError","errorMessage":"koa_exports is not a constructor","stack":["TypeError: koa_exports is not a constructor"," at Object.<anonymous> (/var/task/server.js:17858:11)"," at Module._compile (node:internal/modules/cjs/loader:1358:14)"," at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)"," at Module.load (node:internal/modules/cjs/loader:1208:32)"," at Module._load (node:internal/modules/cjs/loader:1024:12)"," at Module.require (node:internal/modules/cjs/loader:1233:19)"," at require (node:internal/modules/helpers:179:18)"," at _tryRequireFile (file:///var/runtime/index.mjs:1002:37)"," at _tryRequire (file:///var/runtime/index.mjs:1052:25)"," at _loadUserApp (file:///var/runtime/index.mjs:1081:22)"]}

Code

import * as Koa from "koa"
import * as Router from "koa-router";
import serverless from "serverless-http"


const app = new Koa();
app.on('error', (err, ctx) => {
    console.error('server error', err, ctx)
});

const router = new Router();

router
    .get('/api/info', (ctx) => {
        ctx.body = { application: 'sample-app', version: '1' };
    })

app.use(router.routes())
    .use(router.allowedMethods());

module.exports.handler = serverless(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant