[英]Twilio function deployed with TypeScript cannot find module @twilio-labs/serverless-runtime-types
I'm trying to migrate a Twilio functions repo to use TypeScript.我正在尝试迁移 Twilio 函数存储库以使用 TypeScript。 I completely rewritten one of the functions via TypeScript and successfully tested it locally.
我通过TypeScript完全重写了其中一个功能,并在本地测试成功。 However, after I deployed the function, it started returning 500 with the following error:
"message": "Cannot find module '@twilio-labs/serverless-runtime-types'
但是,在我部署 function 后,它开始返回 500 并出现以下错误:
"message": "Cannot find module '@twilio-labs/serverless-runtime-types'
I'm trying to find out how I can correctly import and use types.我正在尝试找出如何正确导入和使用类型。
Some context:一些上下文:
Mainly followed this guide: https://www.twilio.com/blog/twilio-functions-typescript主要遵循本指南: https://www.twilio.com/blog/twilio-functions-typescript
Deployed the repo via: twilio serverless:deploy --functions-folder build/src/functions --runtime node14 --override-existing-project
通过以下方式部署存储库:
twilio serverless:deploy --functions-folder build/src/functions --runtime node14 --override-existing-project
Before compiling to javascript my import statement looks like this:在编译到 javascript 之前,我的导入语句如下所示:
import '@twilio-labs/serverless-runtime-types'; import * as VoiceResponse from '@twilio-labs/serverless-runtime- types/node_modules/twilio/lib/twiml/VoiceResponse'; import { Context, ServerlessCallback, ServerlessFunctionSignature, TwilioClient } from '@twilio-labs/serverless-runtime-types/types';
And after compiling the import statement looks like this:编译导入语句后如下所示:
require("@twilio-labs/serverless-runtime-types");
I tried adding the type dependency @twilio-labs/serverless-runtime-types
as production dependency rather than a dev dependency via npm.我尝试添加类型依赖
@twilio-labs/serverless-runtime-types
作为生产依赖,而不是通过 npm 的开发依赖。
npm i @twilio-labs/serverless-runtime-types -P
I deployed the function again after this change.在此更改后,我再次部署了 function。 Now, I'm not getting the 500 error and the function works as expected.
现在,我没有收到 500 错误,并且 function 按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.