How is dependency resolution for "services/functions" supposed to work? My package.json is not being parsed

20 Views Asked by At

I have a twilio function that I authored using the twilio cli's twilio serverless init command. I then added a couple of dependencies via npm install and implemented it to make a REST call to an external API. At this point, my package.json contained these dependencies:

 "dependencies": {
   "@twilio-labs/serverless-runtime-types": "^3.0.0",
   "@twilio/runtime-handler": "1.3.1",
   "nanoid": "^3.0.2",
   "twilio": "^3.56"
 },

I then deployed the function via the twilio-run deploy command that the project template added to package.json (after figuring out how to authenticate since that doesn't seem to work as documented... but that's a different issue). Reproducing that here for clarity:

./node_modules/.bin/twilio-run deploy --functions-folder dist/functions --assets-folder dist/assets

It deployed successfully and the deployed function's dependency list in the twilio console looked like this: Twilio Console

I then realized I needed to add request signing. So I added a dependency to aws4-axios via npm install. My package.json now contains:

"dependencies": {
   "@twilio-labs/serverless-runtime-types": "^3.0.0",
   "@twilio/runtime-handler": "1.3.1",
   "aws4-axios": "^3.3.4",
   "nanoid": "^3.0.2",
   "twilio": "^3.56"
 },

After deploying again via twilio-run deploy as above, I looked at the function's dependency list in the console, and it is unchanged. Twilio documentation claims to read package.json and provide dependencies from there, but this is manifestly not working, even though I can see new versions being created in the publish log. I can't add this new dependency via the function console because things deployed via CLI are read-only in the console. I thought maybe I could delete the function and re-deploy it, but again, it's apparently read-only and I'm not able to delete it.

How is this stuff supposed to work? Am I doing something wrong here?

1

There are 1 best solutions below

0
IObert On

It's strange that you ran into this issue. I just tried to reproduce it (create a new Functions project -> deploy -> add dependencies with npm i -> redeploy) and it works all fine. Can you check if you are using the latest version of the Twilio CLI?

The other issue, is easier to answer. You can either use the Twilio Console to create and remove "UI Functions" or the Twilio CLI. If you created a Function with the CLI, you can also remove it with this CLI command:

twilio api:serverless:v1:services:remove --sid ZS11111111