twilio-labs / serverless-toolkit

CLI tool to develop, debug and deploy Twilio Functions

Home Page:https://www.twilio.com/docs/labs/serverless-toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't require in a required module

kra opened this issue · comments

A function in my service with the correct dependencies can do this

sip-outgoing.protected.js:

const PNF = require('google-libphonenumber').PhoneNumberFormat;
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
exports.handler = function(context, event, callback) {
    ...

But it cannot do this

sip-outgoing.protected.js:

const theUtilPath = Runtime.getFunctions()['the-util'].path;
const theUtil = require(theUtilPath);
exports.handler = function(context, event, callback) {
    ...

the-util.protected.js:

const PNF = require('google-libphonenumber').PhoneNumberFormat;
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();

When I try that, the function 500s and the logs include

{"message":"Cannot find module 'google-libphonenumber'\nRequire stack: ...

My motivation for doing this is to be able to test the-util.protected.js locally with a unit testing framework.

I am inexperienced with Javascript and Node, so please excuse me if I am not properly verifying.

Thank you so much for opening your first issue in this project! We'll try to get back to it as quickly as possible. While you are waiting...here's a random picture of a corgi (powered by dog.ceo)

picture of dog

Hi @kra were you able to solve it on your side?

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.