You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js中使用Vonage SDK发送SMS报错:TypeError: Vonage is not a constructor

解决Vonage SDK "TypeError: Vonage is not a constructor" 问题

你遇到的问题是因为@vonage/server-sdk的新版本(v3及以上)不再采用默认导出Vonage类,而是使用命名导出,原来的导入写法已经不适用了。

修正步骤:

  1. 调整导入语句,改用解构方式获取Vonage类:
const { Vonage } = require('@vonage/server-sdk')
  1. 新版本中sms.send的参数结构有更新,同时建议在async函数里统一用try/catch替代then/catch(避免混用await和链式调用),修正后的完整代码如下:
const { Vonage } = require('@vonage/server-sdk')

const vonage = new Vonage({
  apiKey: "27945288",
  apiSecret: "************Ek95"
})

const from = "Vonage APIs"
const to = "*********13"
const text = 'A text message sent using the Vonage SMS API'

async function sendSMS() {
  try {
    const resp = await vonage.sms.send({ to, from, text });
    console.log('Message sent successfully');
    console.log(resp);
  } catch (err) {
    console.log('There was an error sending the messages.');
    console.error(err);
  }
}

sendSMS();
  1. 仍然用node sendSMS.js命令执行即可。

内容的提问来源于stack exchange,提问作者Radu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 18:56:14