![](/img/trans.png)
[英]Uncaught Error: Module name “express” has not been loaded yet for context: _
[英]Uncaught Error: Module name “twilio” has not been loaded yet
当我想通过Twilio发送预先完成的SMS消息时,我在终端中收到一个与require
方法有关的错误。 我已经阅读了其他类似的StackOverflow问题,并且尝试在脚本部分index.html
使用CDN for RequireJS,或者使用npm安装Browserify,但是我不确定为什么仍然出现此错误。
Uncaught Error: Module name "twilio" has not been loaded yet for context: _. Use require([])
// 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模块的用途。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.