Per*_*tra 7 typescript serverless-framework
我有一个基于 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
Run Code Online (Sandbox Code Playgroud)
相关的代码块account.ts是:
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
Run Code Online (Sandbox Code Playgroud)
serverless.yml 文件的相关部分是:
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)}`);
...
}
Run Code Online (Sandbox Code Playgroud)
tsconfig.json 相当标准:
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
...
Run Code Online (Sandbox Code Playgroud)
目录树如下所示:
config <dir>
dist <dir>
node_modules <dir>
src <dir>
account.ts
swagger <dir>
package.json
tsconfig.json
webpack.config.js
serverless.yml
Run Code Online (Sandbox Code Playgroud)
想知道我在连接所有点以使其在无服务器中工作时缺少什么吗?
Nis*_*ant 17
您需要提供处理程序的相对路径,这应该可以工作
functions:
account:
handler: "./src/account.handler"
Run Code Online (Sandbox Code Playgroud)
你可以选择省略./,但handler: "src/account.handler"也应该工作。
| 归档时间: |
|
| 查看次数: |
11368 次 |
| 最近记录: |