-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to import Twilio #1016
Comments
Hi @Manbearpixel! I just tried doing the fresh install and it works for me. Things to remember:
|
That is a gigantic undertaking if you don't have it there already. When libraries used in node decide to convert to ESM only, the overwhelming majority of people just use the previous version.
|
Does that mean twilio V4 was working without the package.json requirement but it is not the case with V5? |
Hrmm, actually, no, v5 works with a commonjs project as well. this works fine:
I tried a couple of different combinations with TS, but couldn't reproduce there either. Sorry for the diversion. |
Hi @ehaynes99 @tiwarishubham635 I am still encountering this issue even in Twilio@4. I have not created this project as a "module" only initiative. Mostly because a lot of dependencies don't support ESM, for example: Knex
I was able to get it to work using |
Hey @Manbearpixel! As mentioned by @ehaynes99, we are using axios with 1.6.8. As per the package.json, it supports dual publishing. I would suggest if your project is not module only, you can try using require also |
The error suggests otherwise:
|
I think if you are using with import twilio from 'twilio'
const accountSid = 'xxx'
const authToken = 'xxx' //ENV var
const client = twilio(accountSid, authToken)
client.messages
.create({
body: 'Hello from Twilio',
from: '+1xxx',
to: '+1xxx'
})
.then(message => {
console.log(message.sid)
})
.catch(error => {
console.log(error);
}); However, if const accountSid = 'xxx'
const authToken = 'xxx' //ENV var
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
body: 'Hello from Twilio',
from: '+1xxx',
to: '+1xxx'
})
.then(message => {
console.log(message.sid)
})
.catch(error => {
console.log(error);
}); I hope this answers your queries. |
Closing this issue as no response was received. |
Issue Summary
Fresh install of
twilio
on my node project. Documentation was usingrequire
but I useimport
in my project. When attempting to useimport
I am given this error message:Steps to Reproduce
npm i twilio -S
Code Snippet
Exception/Log
Technical details:
5.0.3
v16.20.2
The text was updated successfully, but these errors were encountered: