使用coffeescript流星的SendGrid sgMail.send错误。作为纯JS工作正常
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用coffeescript流星的SendGrid sgMail.send错误。作为纯JS工作正常相关的知识,希望对你有一定的参考价值。
当我在Coffee中编码时,sgMail.send(msg)调用会产生错误。如果我离开是嵌入式js它工作正常。
这是错误:
I20190305-07:32:50.195(-8)? Exception while invoking method 'sendEmail' RangeError: Maximum call stack size exceeded
I20190305-07:32:50.196(-8)? at Array.forEach (<anonymous>)
I20190305-07:32:50.196(-8)? at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
I20190305-07:32:50.196(-8)? at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
I20190305-07:32:50.196(-8)? at Array.forEach (<anonymous>)
I20190305-07:32:50.196(-8)? at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
I20190305-07:32:50.196(-8)? at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
I20190305-07:32:50.196(-8)? at Array.forEach (<anonymous>)
I20190305-07:32:50.196(-8)? at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
I20190305-07:32:50.196(-8)? at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
I20190305-07:32:50.196(-8)? at Array.forEach (<anonymous>)
I20190305-07:32:50.196(-8)? at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
I20190305-07:32:50.196(-8)? at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
I20190305-07:32:50.197(-8)? at Array.forEach (<anonymous>)
I20190305-07:32:50.197(-8)? at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
I20190305-07:32:50.197(-8)? at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
I20190305-07:32:50.197(-8)? at Array.forEach (<anonymous>)
I20190305-07:32:50.197(-8)? => awaited here:
I20190305-07:32:50.197(-8)? at Promise.await (/Users/paulpedrazzi/.meteor/packages/promise/.0.11.2.a0r1i6.m5ai8++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/promise_server.js:60:12)
I20190305-07:32:50.197(-8)? at Server.apply (packages/ddp-server/livedata_server.js:1634:14)
I20190305-07:32:50.197(-8)? at Server.call (packages/ddp-server/livedata_server.js:1603:17)
I20190305-07:32:50.197(-8)? at MethodInvocation.sendEmail (server/main.coffee:77:12)
I20190305-07:32:50.197(-8)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1767:12)
I20190305-07:32:50.197(-8)? at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
I20190305-07:32:50.198(-8)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1304:12)
I20190305-07:32:50.198(-8)? at DDPServer._CurrentWriteFence.withValue (packages/ddp-server/livedata_server.js:717:46)
I20190305-07:32:50.198(-8)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1304:12)
I20190305-07:32:50.198(-8)? at Promise (packages/ddp-server/livedata_server.js:715:46)
I20190305-07:32:50.198(-8)? at new Promise (<anonymous>)
I20190305-07:32:50.198(-8)? at Session.method (packages/ddp-server/livedata_server.js:689:23)
I20190305-07:32:50.198(-8)? at packages/ddp-server/livedata_server.js:559:43
答案
我不认为const
s是你的问题。在Coffeescript中你可以删除它们。在JS中删除const
不能破坏以前运行的代码(尽管可以添加它们)。这是您的样本转换为coffeescript:
sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
msg =
to: 'test@example.com'
from: 'test@example.com'
subject: 'Sending with SendGrid is Fun'
text: 'and easy to do anywhere, even with Node.js'
html: '<strong>and easy to do anywhere, even with Node.js</strong>'
sgMail.send(msg)
Here you can see the javascript it is converted to
该错误看起来像无限循环或递归函数调用。
如果您将JS代码转换为Coffeescript,请检查缩进,因为Coffeescript将其用于块而不是括号。
如果您可以确定错误来自哪些行,您可以发布该代码,并从中调用它。
以上是关于使用coffeescript流星的SendGrid sgMail.send错误。作为纯JS工作正常的主要内容,如果未能解决你的问题,请参考以下文章
在 coffeescript 类中包装meteor.js 车把模板
使用 SendGrid PHP(sendgrid-php 库)发送文件附件