未捕获错误:模块名称“”;twilio”;尚未加载
Uncaught Error: Module name "twilio" has not been loaded yet
问题
当我想通过Twilio发送预先完成的SMS消息时,我在终端中收到了一个与require
方法有关的错误。我读过其他类似的StackOverflow问题,并尝试在我的脚本部分index.html
中包含RequireJS的CDN,或者npm安装Browserify,但我不确定为什么我仍然会收到错误。
错误
Uncaught Error: Module name "twilio" has not been loaded yet for context: _. Use require([])
scripts.js
// Twilio Credentials
var accountSid = 'AC7*********';
var authToken = '6b6*********';
// Require the Twilio module and create a REST client
var client = require('twilio')(accountSid, authToken);
client.messages.create({
to: "+16479933461",
from: "+12044002143",
body: "There is a new highest bidder. Visit {{websiteUrl}} to place another bid. All proceeds from the silent auction will go to the Samaritian House.",
mediaUrl: "http://farm2.static.flickr.com/1075/1404618563_3ed9a44a3a.jpg",
}, function(err, message) {
console.log(message.sid);
});
这里是Twilio开发人员的传道者。
根据RequireJS错误页面,当像这样使用RequireJS时,应该使用异步加载方法,比如:
// Twilio Credentials
var accountSid = 'AC7*********';
var authToken = '6b6*********';
// Require the Twilio module and create a REST client
require(['twilio'], function(twilio){
var client = twilio(accountSid, authToken);
client.messages.create({
to: "+16479933461",
from: "+12044002143",
body: "There is a new highest bidder. Visit {{websiteUrl}} to place another bid. All proceeds from the silent auction will go to the Samaritian House.",
mediaUrl: "http://farm2.static.flickr.com/1075/1404618563_3ed9a44a3a.jpg",
}, function(err, message) {
console.log(message.sid);
});
});
如果这是在终端中,我可以问你为什么使用RequireJS吗?Node.js内置了require
,并且是同步的。
我想知道你是否正在尝试在前端使用Twilio模块?如果是这样的话,你不应该暴露你的帐户凭据,这可能会被用来滥用你的帐户。在服务器上执行Twilio API请求更好、更安全。这就是Node.js模块的作用。
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 如何在生成下载文件时显示加载动画
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 无法在通过jQuery的ajax加载的页面中执行javascript
- Emberjs应用程序加载在除Index之外的所有路由上
- 在chrome.tabs.onCreated之后加载HTML页面
- 单击F5时如何停止页面加载
- HTML5音频加载和播放获胜'我不能在iPad上工作
- 跟踪在页面加载时应用内联样式的JavaScript
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- jQuery Lazy加载动画滚动
- Html页面上的多个Base64图像和平滑加载
- 如何创建带有插槽的vue js组件预加载程序
- Webpack/Rect:遵循egghead.io教程,但出现错误:您可能需要一个合适的加载程序来处理此文件类型
- 如何使该数据在所有元素中加载
- Chrome扩展没有't在重新加载之前考虑期权价值
- 使用javascript在Flash中加载外部图像
- Ajax文件加载和<输入>文件加载
- 未捕获错误:模块名称“”;twilio”;尚未加载
- 是否可以用webpack加载twilio.js库?