ModuleParse失败或找不到

ModuleParse Failed or Not Found

本文关键字:找不到 失败 ModuleParse      更新时间:2024-03-23

我正在构建一个网络应用程序,允许用户通过Twilio API输入电话号码和发送短信。我已经在一个文件中构建了该功能,如下所示。如果我将cd发送到此文件并运行node twilioActions.js,则会发送文本消息。

var client = require('twilio')(CLIENT_ID, CLIENT_SECRET);
// ideally, I'd like to send the message using this method and call this from other JavaScript files
export const sendMessage = () => {
}
// the following code works when I run 'node twilioActions.js'
client.sendMessage({
  to:'...', 
  from: '...', 
  body: 'Text message test.' 
}, function(err, responseData) { 
  if (!err) { 
    console.log(responseData.from); // outputs "+14506667788"
    console.log(responseData.body); // outputs "word to your mother."
  }
});

但是,我想从不同的React文件中调用sendMessage方法。给你:

import * as twilioActions from './twilioActions';
class PhoneView extends React.Component{
  // other methods are hidden obviously, the one below is called when a button is pressed to send a message.
  sendMessage() {
    twilioActions.sendMessage();
  }
}

当我试图构建项目时,我会得到以下错误:

ERROR in ./~/twilio/package.json
Module parse failed:/Users/Felix/Desktop/ECE590/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
ERROR in ./~/request/lib/har.js
Module not found: Error: Cannot resolve module 'fs' in /Users/Felix/Desktop/ECE590/node_modules/request/lib
 @ ./~/request/lib/har.js 3:9-22
ERROR in ./~/tunnel-agent/index.js
Module not found: Error: Cannot resolve module 'net' in /Users/Felix/Desktop/ECE590/node_modules/tunnel-agent
 @ ./~/tunnel-agent/index.js 3:10-24
ERROR in ./~/tunnel-agent/index.js
Module not found: Error: Cannot resolve module 'tls' in /Users/Felix/Desktop/ECE590/node_modules/tunnel-agent
@ ./~/tunnel-agent/index.js 4:10-24

我觉得我犯了一个简单的错误,可能没有使用正确的库或包含正确的参考文献。有人能为我指明正确的方向吗?非常感谢!

这里是Twilio开发人员的传道者。

twilio npm模块未构建或建议在前端使用。最重要的是,你需要在网站的前端代码中公开你的帐户凭据。这是一个安全风险,因为这意味着恶意攻击者可能会掌握你的凭据并滥用你的Twilio帐户。

我建议您在服务器端创建一个服务,您可以通过AJAX请求调用它来执行这样的操作。