Closed LouisPennachio closed 6 years ago
what does your app.js module export?
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const express = require("express");
const bodyParser = require("body-parser");
const routes_1 = require("./routes/routes");
class App {
constructor() {
this.routes = new routes_1.Routes();
this.app = express();
this.config();
this.routes.routes(this.app);
}
config() {
// Parser setup
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({ extended: true }));
}
}
exports.default = new App().app;
//# sourceMappingURL=app.js.map
I assume es6 modules might be the problem there. Lambda/claudia baseline is still Node 6, so es6 modules aren’t supported. try exporting the app directly instead of exports.default. Alternatively, change the generated lambda file to load the app from the app module correctly. it just does a require rather than import, so you might fix it by importing.
Indeed !
Changing the export line from :
exports.default = new App().app;
To :
module.exports = new App().app;
did the trick. Thank you :)
Hello.
I'm running into the same exact error here and I've downgraded from es6 to es5. And my code has the export correctly.
import * as express from 'express';
export class App { public app: express.Application; constructor() { this.app = express(); } } module.exports = new App().app; ` I have: Node v8.11.3 npm 6.9.0 webpack 2.4.1
@dolosplus you can't use ES modules with node 8, that's not supported in that node version. this has nothing to do with claudia.
Thank you. That means I can't use Node 10/11 with Claudia either since AWS Lambda only support up to Node 8 ?
@dolosplus in theory, you could deploy Node 10/11 as a new runtime to Lambda in a layer, then link to that layer when deploying with claudia (see https://claudiajs.com/news/2019/01/07/claudia-5.3.html). If this is too much magic for you, you'll need to wait for official support for Node 10 in AWS Lambda.
Thank you. I forgot to mention that I also use Webpack to build my TS scripts into a single JS file with ES5 and use Claudia to proxy and deploy to Lambda. Would that still be possible without using Layers?
I am following the tutorial to deploy a helloworld express app (using typescript).
I first generated my express wrapper using :
claudia --source dist generate-serverless-express-proxy --express-module app
It did not produce any error. Then I tried to deploy this to AWS using :
claudia create --source dist --handler lambda.handler --runtime nodejs8.10 --region eu-west-1
which produced this error :
So the problem is apparently coming from aws-serverless-express/index.js:155
Here it is :
I am not sure how to investigate any further, is this a bug or am I doing something wrong ?