Claudia.js create 在 typescript 项目中找不到模块 lambda

Claudia.js create cannot find module lambda in typescript project

搜索了几个小时后,我不知道如何在我的项目中正确地 运行 claudia create

this turoial 之后,我在 AWS 控制台创建了一个组和一个用户,然后我将密钥添加到我的 .aws/credentials 文件中。

然后我 运行 这个正确生成 lambda.js 文件的命令:

claudia --source dist generate-serverless-express-proxy --express-module app

我的lambda.js

'use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const binaryMimeTypes = [
    'application/octet-stream',
    'font/eot',
    'font/opentype',
    'font/otf',
    'image/jpeg',
    'image/png',
    'image/svg+xml'
]
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context)

然后我尝试在 AWS 上部署 lambda 函数:

claudia create --source dist --profile myprofile --handler lambda.handler --deploy-proxy-api --region eu-west-1

但是我得到了这个错误:

validating package TypeError: "listener" argument must be a function at _addListener (events.js:239:11) at Server.addListener (events.js:297:10) at new Server (_http_server.js:269:10) at Object.createServer (http.js:34:10) at Object.createServer (/tmp/IiRPif/my-project-1.0.0-1Yh6Wb/package/node_modules/aws-serverless-express/index.js:155:25) at Object. (/tmp/IiRPif/my-project-1.0.0-1Yh6Wb/package/lambda.js:13:37) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at validatePackage (/usr/local/lib/node_modules/claudia/src/tasks/validate-package.js:16:15) at initEnvVarsFromOptions.then.then.then.then.then.then.then.dir (/usr/local/lib/node_modules/claudia/src/commands/create.js:342:10) at cannot require ./lambda after clean installation. Check your dependencies.

我做错了什么?

我的package.json

{ 
  "name": "...",
  "version": "1.0.0",
  "scripts": {
    "build": "tsc -p tsconfig.json & cp \"package.json\" \"dist/package.json\"
  },
  "repository": {
    "type": "git",
    "url": "..."
  },
  "homepage": "...",
  "dependencies": {
    "body-parser": "^1.18.3",
    "express": "^4.16.3",
    "mongoose": "^5.2.7",
    "nodemon": "^1.18.3"
  },
  "devDependencies": {
    "typescript": "^3.0.1"
  }
}

我的app.ts

import * as express from "express";
import * as bodyParser from "body-parser";
import * as mongoose from "mongoose";
import { Routes } from "./routes/routes";

class App {

    public app: express.Application;
    public routes: Routes = new Routes();

    constructor() {
        this.app = express();

        // Parser setup
        this.app.use(bodyParser.json());
        this.app.use(bodyParser.urlencoded({ extended: true }));

        this.routes.routes(this.app);            
    }
}

exports.default = new App().app;

discussion on Claudia's github 之后,这似乎是 es6 和 claudia/lambda 之间的兼容性问题。

我需要做的就是将 app.js 文件中的这一行从 :

更改为
exports.default = new App().app;

收件人:

module.exports = new App().app;