我想通過Twilios npm包發送一個簡單的短信,我已經嘗試了一些當前的包無法使用。所以我認爲我會去古老的npm路線。這也似乎在以下服務器錯誤消息失敗:通過Twilio npm包發送短信 - 錯誤無法找到 - 錯誤:找不到模塊'./webhooks'
W20170306-13:50:46.118(-8)? (STDERR) Error: Cannot find module './webhooks' W20170306-13:50:46.118(-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 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 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) 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) at /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)
這是我的服務器代碼:
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);
});
我也開到Twilio的工作以外的解決方案,如果有的話。謝謝!
確保您使用NPM封裝,流星正確。你不應該使用require,而應該使用import。請參閱[流星指南](https://guide.meteor.com/using-npm-packages.html) – jordanwillis
正如@jordanwillis所述。您不應該在Meteor中使用require來導入節點打包。閱讀流星指南並使用「導入」;從'twilio'導入Twilio; – AshHimself