typescript - 通过无服务器失败的 Typescript 编译
问题描述
我有一个基于 Typescript 的 Lambda 函数,可以很好地编译,tsc
但是当我尝试通过无服务器部署时,Typescript 复杂性失败并出现以下错误:
Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
Serverless: Warning: "rootDir" from local tsconfig.json is overriden
Cannot locate handler - account. not found
Error --------------------------------------------------
Error: Typescript compilation failed. Please ensure handlers exists with ext .ts or .js
at /Users/bob/Development/service-account/node_modules/serverless-plugin-typescript/src/typescript.ts:69:13
相关的account.ts
代码块是:
import { APIGatewayProxyHandler, APIGatewayEvent, Context } from 'aws-lambda';
import 'source-map-support/register';
export const handler: APIGatewayProxyHandler = async (event: APIGatewayEvent, context: Context): Promise<any> => {
console.debug(`event: ${JSON.stringify(event, null, 1)}`);
console.debug(`context: ${JSON.stringify(context, null, 1)}`);
...
}
serverless.yml 文件的相关部分是:
plugins:
- serverless-iam-roles-per-function
- serverless-plugin-typescript
- serverless-webpack
service: accounts
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
functions:
account:
handler: account.handler
...
tsconfig.json 相当标准:
{
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"lib": [
"es2020",
"dom"
],
"strict": true,
"esModuleInterop": true,
"rootDir": "./src",
"outDir": "./dist",
},
"include": [
"./src/*.ts"
],
"exclude": [
"node_modules"
]
}
目录树如下所示:
config <dir>
dist <dir>
node_modules <dir>
src <dir>
account.ts
swagger <dir>
package.json
tsconfig.json
webpack.config.js
serverless.yml
关于连接所有点以使其在无服务器中工作的想法我缺少什么?
解决方案
您需要提供处理程序的相对路径,这应该可以
functions:
account:
handler: "./src/account.handler"
您可以选择省略./
并且handler: "src/account.handler"
也应该工作。
推荐阅读
- java - Java FileDialog browse and read from file
- android - GPS跟踪系统?
- python - 如何在python中获取属性的setter方法的属性
- c - 源路径中有空格时 VS Code 调试失败
- python - Any way to read number of active workers of gunicorn managed by the arbiter from command line?
- c++ - Access static variable from CPP file to other header file
- angular - Angular 2 Route Translation
- node.js - 'apidoc' is not recognized as an internal or external command
- kernel - 内核问题,试图解决触摸板问题
- c# - (统一)溢出异常??实施无代码 IAP