twilio / twilio-node

Node.js helper library
MIT License
1.39k stars 507 forks source link

url.URL is not a constructor in twilio nodjs library #674

Closed lakshminagandla closed 3 years ago

lakshminagandla commented 3 years ago

I have tried with below versions

node: 12.18.3 npm: 6.14.6 twilio: 3.63.0

We got below error message:

url.URL is not a constructor node_modules/twilio/lib/rest/Twilio.js:261:1 259 | } 260 |

261 | var uri = new url.URL(opts.uri); | ^ 262 | uri.hostname = this.getHostname(uri.hostname, this.edge, this.region); 263 | 264 | return this.httpClient.request({

Printing stack trace:

at Twilio.request (webpack:///node_modules/twilio/lib/rest/Twilio.js:261:1) at Api../node_modules/twilio/lib/base/Domain.js.Domain.request (webpack:///node_modules/twilio/lib/base/Domain.js:34:1) at V2010../node_modules/twilio/lib/base/Version.js.Version.request (webpack:///node_modules/twilio/lib/base/Version.js:45:1) at V2010../node_modules/twilio/lib/base/Version.js.Version.page (webpack:///node_modules/twilio/lib/base/Version.js:154:1) at Function.page (webpack:///node_modules/twilio/lib/rest/api/v2010/account/message.js:355:1) at apply (webpack:///node_modules/lodash/lodash.js:488:1) at wrapper (webpack:///node_modules/lodash/lodash.js:5379:1) at fetchNextPage (webpack:///node_modules/twilio/lib/rest/api/v2010/account/message.js:217:1) at Function.each (webpack:///node_modules/twilio/lib/rest/api/v2010/account/message.js:243:1) at Function.list (webpack:///node_modules/twilio/lib/rest/api/v2010/account/message.js:305:1)

Please suggest the solution

lakshminagandla commented 3 years ago

I have tried with below versions

node: 12.18.3 npm: 6.14.6 twilio: 3.63.0

We got below error message:

url.URL is not a constructor node_modules/twilio/lib/rest/Twilio.js:261:1 259 | } 260 |

261 | var uri = new url.URL(opts.uri); | ^ 262 | uri.hostname = this.getHostname(uri.hostname, this.edge, this.region); 263 | 264 | return this.httpClient.request({

Printing stack trace:

at Twilio.request (webpack:///node_modules/twilio/lib/rest/Twilio.js:261:1) at Api../node_modules/twilio/lib/base/Domain.js.Domain.request (webpack:///node_modules/twilio/lib/base/Domain.js:34:1) at V2010../node_modules/twilio/lib/base/Version.js.Version.request (webpack:///node_modules/twilio/lib/base/Version.js:45:1) at V2010../node_modules/twilio/lib/base/Version.js.Version.page (webpack:///node_modules/twilio/lib/base/Version.js:154:1) at Function.page (webpack:///node_modules/twilio/lib/rest/api/v2010/account/message.js:355:1) at apply (webpack:///node_modules/lodash/lodash.js:488:1) at wrapper (webpack:///node_modules/lodash/lodash.js:5379:1) at fetchNextPage (webpack:///node_modules/twilio/lib/rest/api/v2010/account/message.js:217:1) at Function.each (webpack:///node_modules/twilio/lib/rest/api/v2010/account/message.js:243:1) at Function.list (webpack:///node_modules/twilio/lib/rest/api/v2010/account/message.js:305:1)

Please suggest the solution

JenniferMah commented 3 years ago

Hi @LakshmiNagandla are you using twilio-node in a client side app? Twilio-node should not be used in a client-side app since communicating with Twilio APIs requires auth. These credentials could be exposed to the end-user. Here's a blog about this and how to re-architect: twilio.com/blog/send-an-sms-react-twilio

SavvasLakshmiNagandla commented 3 years ago

@JenniferMah, We are trying to read the messages that are received to the Twilio number. While we are using APIs to read the data we are getting the above issue that we are mentioned.

But now at this moment, we are able to resolve the issue with a small update on the library side. Seems inside the Twilio library, we have noticed below the "Twilio.js" file, we are calling "var uri = new url.URL(opts.uri);"

File location: Twilio.request (webpack:///node_modules/twilio/lib/rest/Twilio.js:261:1)

Here we just tweaked the code like "var uri = new URL(opts.uri);" and now the library started working without any issues.

Thanks for your response and due to priority tasks we are unable to acknowledge you.

Thanks & Regards, Lakshmi

shwetha-manvinkurke commented 3 years ago

@SavvasLakshmiNagandla can you clarify if you are using the node helper in a client side app?

shwetha-manvinkurke commented 3 years ago

Closing due to inactivity. Feel free to reopen if further help is needed.