【问题标题】:Type Error: require(...) is not a function in SendGrid NodeJS类型错误:require(...) 不是 SendGrid NodeJS 中的函数
【发布时间】:2016-06-24 09:44:19
【问题描述】:

我正在尝试使用 sendrid 上的以下文档发送电子邮件:

https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/nodejs.html

我的 app.js 看起来像这样:

var sendgrid = require('sendgrid')('SENDGRID_APIKEY');

运行 npm start 时出现以下错误:

var sendgrid  = require('sendgrid')(conf);
                               ^
TypeError: require(...) is not a function
  at Object.<anonymous> (C:\Users\Grandullon\Desktop\angular\app.js:8:36)
  at Module._compile (module.js:409:26)
  at Object.Module._extensions..js (module.js:416:10)
  at Module.load (module.js:343:32)
  at Function.Module._load (module.js:300:12)
  at Module.require (module.js:353:17)
  at require (internal/module.js:12:17)
  at Object.<anonymous> (C:\Users\Grandullon\Desktop\angular\bin\www:7:11)
  at Module._compile (module.js:409:26)
  at Object.Module._extensions..js (module.js:416:10)

任何想法我做错了什么? conf 是我存储 API 密钥的变量。

我正在使用干净的快速安装。

谢谢

我的 package.json 可以按要求在这里查看:

http://pastebin.com/pGKWFReX

【问题讨论】:

  • 能给我们看看你的 package.json 文件吗?
  • 是的,package.json 中不存在问题,我的错。看看 @Akash 的回答,这与导致问题的原因很相符。

标签: node.js express sendgrid


【解决方案1】:

latest documentation 显示了不同的初始化结构。

你应该尝试做

var sg = require('sendgrid').SendGrid(conf);

【讨论】:

  • 使用该初始化工作!所以我认为另一个版本必须停止工作。我将联系 SendGrid 支持人员进行检查。谢谢
  • 我认为如果您下载旧版本的软件包,旧版本将可以工作。如果某些业务需求迫使您使用较旧的 api,您可以随时切换到 npm install sendgrid-nodejs@2,尽管我不知道 Sendgrid 是否会支持。
  • Awesone,我试试看。我只是在测试服务,所以手头没有业务需求。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-26
  • 2013-04-01
  • 2016-03-06
  • 1970-01-01
  • 2021-01-25
相关资源
最近更新 更多