简体   繁体   English

通过Twilio npm包发送短信 - 错误找不到 - 错误:找不到模块'./webhooks'

[英]Send SMS via Twilio npm package - Error cannot find - Error: Cannot find module './webhooks'

I am trying to send a simple SMS via Twilios npm package, I have tried some of the current packages out there with no avail. 我试图通过Twilios npm包发送一个简单的短信,我已经尝试了一些当前的包没有用。 So I thought I would go the good old fashioned npm route. 所以我想我会选择老式的npm路线。 That also seems to fail at the following server error message: 这似乎也失败了以下服务器错误消息:

W20170306-13:50:46.118(-8)? W20170306-13:50:46.118(-8)? (STDERR) Error: Cannot find module './webhooks' W20170306-13:50:46.118(-8)? (STDERR)错误:找不到模块'./webhooks'W20170306-13:50:46.118(-8)? (STDERR) at require (packages/modules-runtime.js:123:19) W20170306-13:50:46.119(-8)? (STDERR)at require(packages / modules-runtime.js:123:19)W20170306-13:50:46.119(-8)? (STDERR) at meteorInstall.node_modules.twilio.lib.index.js (packages/modules.js:342:16) W20170306-13:50:46.119(-8)? (STDERR)at meteorInstall.node_modules.twilio.lib.index.js(packages / modules.js:342:16)W20170306-13:50:46.119(-8)? (STDERR) at fileEvaluate (packages/modules-runtime.js:197:9) W20170306-13:50:46.119(-8)? (STDERR)在fileEvaluate(packages / modules-runtime.js:197:9)W20170306-13:50:46.119(-8)? (STDERR) at require (packages/modules-runtime.js:120:16) W20170306-13:50:46.120(-8)? (STDERR)at require(packages / modules-runtime.js:120:16)W20170306-13:50:46.120(-8)? (STDERR) at meteorInstall.server.server.js (server/server.js:3:14) W20170306-13:50:46.120(-8)? (STDERR)at meteorInstall.server.server.js(server / server.js:3:14)W20170306-13:50:46.120(-8)? (STDERR) at fileEvaluate (packages/modules-runtime.js:197:9) W20170306-13:50:46.120(-8)? (STDERR)在fileEvaluate(packages / modules-runtime.js:197:9)W20170306-13:50:46.120(-8)? (STDERR) at require (packages/modules-runtime.js:120:16) W20170306-13:50:46.121(-8)? (STDERR)at require(packages / modules-runtime.js:120:16)W20170306-13:50:46.121(-8)? (STDERR) at /Users/nicholas/Desktop/meteor/esoLounge/.meteor/local/build/programs/server/app/app.js:15:1 W20170306-13:50:46.123(-8)? (STDERR)/Users/nicholas/Desktop/meteor/esoLounge/.meteor/local/build/programs/server/app/app.js:15:1 W20170306-13:50:46.123(-8)? (STDERR) at /Users/nicholas/Desktop/meteor/esoLounge/.meteor/local/build/programs/server/boot.js:303:34 W20170306-13:50:46.124(-8)? (STDERR)/Users/nicholas/Desktop/meteor/esoLounge/.meteor/local/build/programs/server/boot.js:303:34 W20170306-13:50:46.124(-8)? (STDERR) at Array.forEach (native) (STDERR)在Array.forEach(本机)

This is my server code: 这是我的服务器代码:

let accountSid = 'ACxxxxxxxxxxxxxxxxxxxxa',
    authToken = 'a91xxxxxxxxxxxxxxxxxxxxxxxxxa',
    twilio = require("../node_modules/twilio/lib"),
    client = new twilio.RestClient(accountSid, authToken);

client.messages.create({
    body: 'Hello from Node',
    to: '+15555555551', 
    from: '+15555555551'
}, function(err, message) {
    console.log(message.sid);
});

I am also open to working solutions outside of Twilio, if there is any. 如果有的话,我也愿意接受Twilio以外的工作解决方案。 Thanks! 谢谢!

Why are you requiring twilio like that (with the file path)? 你为什么要这样的twilio(使用文件路径)? Node/npm/require handles all that for you automatically and I imagine that's where your problem is coming from. Node / npm / require会自动处理所有这些,我想这就是问题的来源。

Just do: 做就是了:

var client = require('twilio')(accountSid, authToken);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM