Twilio SMS Notification: The Class extension value provided is not a valid constructor or null

When attempting to utilize Twilio for sending SMS messages in a Vue.js project, I encountered an error while accessing Tools -> Developer Tools.

<template>
 <div>
   <input type="text" v-model="to" placeholder="Phone number">
   <textarea v-model="body" placeholder="Message"></textarea>
   <button @click="sendSMS">Send SMS</button>
 </div>
</template>

<script>
import twilio from 'twilio';

export default {
 data() {
   return {
     to: '',
     body: '',
     accountSid: 'YOUR_TWILIO_ACCOUNT_SID',
     authToken: 'YOUR_TWILIO_AUTH_TOKEN',
     twilioNumber: 'YOUR_TWILIO_NUMBER',
   };
 },
 methods: {
   async sendSMS() {
     const client = twilio(this.accountSid, this.authToken);

     try {
       await client.messages.create({
         body: this.body,
         from: this.twilioNumber,
         to: this.to,
       });
       alert('SMS sent successfully!');
     } catch (error) {
       console.error('Error sending SMS:', error);
       alert('Error sending SMS. Please try again.');
     }
   },
 },
};
</script>

The following error occurred:

twilio.js?t=17137716…939&v=b4dcae58:2609 Uncaught TypeError: Class extends value undefined is not a constructor or null
   at twilio.js?t=17137716…&v=b4dcae58:2609:36
   at ../../../node_modules/agent-base/dist/src/index.js (twilio.js?t=17137716…9&v=b4dcae58:2763:7)

I have installed the npm package 'twilio' and specified it in my package.json as: "twilio": "^5.0.4"

Answer №1

agent-base and twilio are both Node libraries, but an error is occurring due to a missing class specific to the Node API in the code.

It is not safe to run these libraries on the client side as it would require exposing private API keys. Therefore, they should be used on a Node server with requests made from a Vue application.

If unsure, always refer to the library's documentation. While some Node libraries assume developers understand how to use them within context, twilio explicitly states this:

This library is compatible with:

Node.js 14

Node.js 16

Node.js 18

Node.js LTS (20)

TypeScript versions 2.9 and above are also supported.

Warning: Avoid using this Node.js library in frontend applications as it can expose Twilio credentials to end-users through bundled HTML/JavaScript.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be the reason that a basic click function fails to locate the selector?

I have created a quick JavaScript module that opens an image and fades out a container to reveal the image. The HTML markup for the image looks like this: <div style="margin-bottom:1px;" class="rsNavItem rsThumb front"> <di ...

Session Redirect Error in Express.js

Encountering an error consistently when running my code with the pseudocode provided below (Just to clarify, my code is built on the react-redux-universal-hot-example) Error: Can't set headers after they are sent. [2] at ServerResponse.OutgoingMe ...

How can we accurately identify the server that initiated an AJAX call in a secure manner?

Imagine a scenario where Site A embeds a JavaScript file from Server B and then makes a JSONP or AJAX request to a resource on Server B. Is there any foolproof way for Server B to determine that the specific JSONP request originated from a user on Site A, ...

Error message encountered: Missing property status in TypeScript code

An error occurs in the refetchInterval when accessing data.status, with a message saying "property status does not exist" chatwrapper.tsx const ChatWrapper = ({ fileId }: ChatWrapperProps) => { const { data, isLoading } = trpc.getFileUploadStatus.use ...

Encountering difficulties retrieving information from an API using Angular

I am encountering an issue while trying to retrieve data from an API. When I use console.log() to view the data, it shows up in the console without any problem. However, when I attempt to display this data in a table, I keep receiving the error message: ER ...

Can you explain the significance of network activity groupings within the Firebug Net tab?

Can you explain the significance of different splitter lines on the Net tab in Firebug? In this screenshot, line 1 and 2 appear to be grouped together. However, line 3 stands alone. What do these groupings represent? ...

Updating input text value using jQuery - Chrome extension

I have been attempting to modify the input value on a specific website using a Chrome extension. To achieve this, I am utilizing jQuery in my content script. While it is effective in most scenarios, I encountered difficulty changing the input value when ...

Navigate to Element ID with Nuxt.js on click

Currently, I am in the process of developing a Nuxt application and facing a challenge. I want the page to automatically scroll down to a specific element after clicking on a button. Interestingly, the button and the desired element are located within diff ...

How can I swap a string for a symbol in JavaScript?

Is there a way to convert the text @abc some text here to <a href="some_url">@abc</a> some text here using JavaScript? Are there any libraries that can help with this task? ...

Mounting Vue.js 3 component instances during execution time

I'm currently experimenting with vue-leaflet/vue-leaflet and I want to have multiple instances of <l-polyline> within the <l-map> component. However, I am unsure how to achieve this. Initial version (map displaying a pre-drawn polyline): ...

Update a Div, Table, or TR element without the need for a page reload or Ajax usage

How can I refresh a div, table or <tr>? The data displayed is not coming from a database, it's just a simple error block and the value comes from Java-script. The issue arises when a user inputs a value in a textbox, the value gets stored in th ...

What sets apart Vue-Test-Utils' "mount" from "shallowMount"?

Just to clarify, my experience with Vue, JavaScript, and web frameworks is still pretty fresh. Currently, I am working on getting more familiar with basic unit and component testing using Jest and vue-test-utils. I have gone through the documentation for ...

Extract string data from JSON payload

How can I extract the itemlocation from itemInfo and display it in a new column in my react table using Material UI? While I know this can be done on the backend, I am looking for a way to achieve this without backend involvement. Below is an example of ho ...

Discovering the channel editor on Discord using the channelUpdate event

While working on the creation of the event updateChannel, I noticed that in the Discord.JS Docs, there isn't clear information on how to identify who edited a channel. Is it even possible? Below is the current code snippet that I have: Using Discord. ...

Hide the menu when a user taps on an item on mobile or tablet devices

I'm facing a unique challenge and could use some guidance. The issue is with the mobile version of my website, accessible at . On tablets or mobile devices, the menu is condensed into a button. To navigate through the menu, I have to click the button ...

Shut down a pop-up overlay

I've been facing a challenge in implementing greasemonkey to automatically close a modal when the "x" button is clicked. Allow me to share with you the code snippet for the webpage: <div class="modal-header"> <button type="button" class="clo ...

Error encountered when deploying the app to the live server: 500 Internal Server Issue

I am encountering an issue with my ASP.Net web app's ajax file upload feature. While it works perfectly on my local host machine during testing, I face a 500 Internal Server error when I try to publish it to a website. The console output in Google Chr ...

Tips for controlling the embla carousel based on breakpoints in a React application

Trying to toggle the Embla Carousel on and off based on different breakpoints using the React version. I have attempted to initialize it for mobile and destroy it for tablet upwards, but it seems like the reinitialization is not working as expected. I su ...

What is the best method for transferring a string from JavaScript to a JSON file?

Is there a way to update the value of "JSValue" in my JSON (JSValue) using JavaScript? Specifically, how can I assign JSValue to a variable called Value using JavaScript? JavaScript var Value = 1 + 1 JSON { "DATA": [ { "JSValue": "0" } ...

How can we stop Vuetify from overwriting Bootstrap3's classes when using treeshaking?

I am currently in the process of transitioning an app from jQuery/Bootstrap3 to Vue/Vuetify. My approach is to tackle one small task at a time, such as converting the Navbar into its own Vue component and then gradually updating other widgets. Since the n ...