0

I'm trying to migrate a Twilio functions repo to use TypeScript. I completely rewritten one of the functions via TypeScript and successfully tested it locally. However, after I deployed the function, it started returning 500 with the following error: "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

  • Deployed the repo via: twilio serverless:deploy --functions-folder build/src/functions --runtime node14 --override-existing-project

  • Before compiling to javascript my import statement looks like this:

    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");
    

1 Answer 1

2

I tried adding the type dependency @twilio-labs/serverless-runtime-types as production dependency rather than a dev dependency via npm.

npm i @twilio-labs/serverless-runtime-types -P

I deployed the function again after this change. Now, I'm not getting the 500 error and the function works as expected.

Sign up to request clarification or add additional context in comments.

2 Comments

Accepting this workaround as an answer until someone provides a better solution...
In the blog post you followed, the @twilio-labs/serverless-runtime-types were installed as a production dependency, not a dev dependency, so this is the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.