Twilio + Nodejs react app. Cannot find module “net”

风格不统一 提交于 2019-12-12 01:36:34

问题


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.


回答1:


According to error message you need specify appropriate loader for json files (it requires here) in your webpack-config.

{test: /\.json$/, loader: 'json'}



回答2:


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.



来源:https://stackoverflow.com/questions/35914213/twilio-nodejs-react-app-cannot-find-module-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!