I have installed twilio from npm and it shows in my list of packages as twilio [v.4.9.0].
I have the following statement in a backend .jsw module
import twilio from ‘twilio’;
Yet it gives me the following error
“message”:“[“Error loading web module backend/profile.jsw: Cannot find module ‘twilio’\nRequire stack:\n- /user-code/backend/profile.jsw\n- /user-code/stubmodule-that-does-the-require.js\n- /cloud-runtime-code/node_modules/scoped-require/index.js\n- /cloud-runtime-code/packages/elementory/cloud-runtime/factories.js\n- /cloud-runtime-code/packages/elementory/cloud-runtime/create-app.js\n- /cloud-runtime-code/packages/elementory/cloud-runtime/cloud-grid-runner.js”]”
This is the same code I used for another website, and it used to work. The only difference is the other one was twilio [v.3.55.0] and not [v.4.9.0]
It loads perfectly fine if I put the code in a client side file.
Please help.
My backend code:
import twilio from ‘twilio’ ;
import { getSecret } from ‘wix-secrets-backend’ ;
export async function testSMS ( )
{
console . log ( ‘Inside testSMS in backend/testTwilio’ );
**const** accountSID = **await** getSecret ( "T_SID" );
**const** authToken = **await** getSecret ( "T_TOKEN" );
**const** from_pn = **await** getSecret ( "T_PN" );
**let** client = **new** twilio ( accountSID , authToken );
**let** pnStr = '+14085550101' ; // This is just a fake number.
**return** **await** client . messages . create ({
body : 'test' ,
to : pnStr ,
**from** : from_pn
});
}