当我在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
答案 0 :(得分:0)
我不认为const
是您的问题。在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会将其用于块而不是大括号。
如果您可以弄清错误来自何行,则可以发布该代码以及从何处调用该代码。