I'm trying to create a web app using React and Express and using webpack-dev-server for development. I want to send text messages but I keep getting this error when I try to use Twilio or Plivo Uncaught Error: Cannot find module "net"
Another error I get is:
./~/twilio/package.json
Module parse failed: /Users/H/github/app/node_modules/twilio/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "_args": [
| [
| "twilio",
@ ./~/twilio/lib/Client.js 5:17-43
And I get a lot more of errors similar to that one. I'm trying to follow the example Twilio has in the docs but just by requiring twilio in the app it gives me those errors.
Twilio developer evangelist here.
The twilio module for Node.js is not recommended to be used in the front end, so is not built for the front end. The library uses your Account Sid and Auth Token from your Twilio account to authenticate with the API. You should keep those credentials secret, otherwise an attacker could steal them and use your Twilio account.
We recommend making calls to the Twilio API from your own server. You could then build a React component to make calls to that server via AJAX, rather than calling the API directly in the front end.
According to error message you need specify appropriate loader for json files (it requires here) in your webpack-config.