Sendgrid-nodejs: deepMergeDynamicTemplateData

创建于 2019-01-03  ·  4评论  ·  资料来源: sendgrid/sendgrid-nodejs

将其放入 lambda 的 netlify 函数处理程序中

// For more info, check https://www.netlify.com/docs/functions/#javascript-lambda-functions
export function handler(event, context, callback) {
  console.log('sending')
  console.log(event)
  console.log(context)

  const sgMail = require('@sendgrid/mail')
  sgMail.setApiKey(process.env.SENDGRID_API_KEY)
  const msg = {
    to: '[email protected]',
    from: '[email protected]',
    templateId: '#ID',
    dynamic_template_data: {
      recipient: 'alex',
    },
  }
  sgMail.send(msg).catch(function(error) {
    console.log(error)
  })
  console.log('sent sign up')
}

我得到以下

TypeError: s is not a function
    at e.exports.deepMergeDynamicTemplateData (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:127:27164)
    at p.applyDynamicTemplateData (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:117545)
    at p.addPersonalization (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:116796)
    at p.addTo (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:116994)
    at p.fromData (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:115579)
    at new p (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:114482)
    at Function.create (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:120622)
    at e.exports.send (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:1:156753)
    at Object.a.handler (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:127:36900)
    at /Users/amlcodes/Documents/projects/cctmvp/node_modules/netlify-lambda/lib/serve.js:79:27
    at Layer.handle [as handle_request] (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/route.js:137:13)
    at next (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/route.js:131:14)
    at next (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/route.js:131:14)
    at next (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/route.js:131:14)
    at next (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/route.js:131:14)
[HPM] Error occurred while trying to proxy request mailinglist from localhost:8000 to http://localhost:9000 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)

有了这个电话

fetch('/.netlify/functions/mailinglist', {
      method: 'POST',
      body: JSON.stringify({
        // recipient: this.state.recipient,
        recipient: 'alex',
      }),
      headers: new Headers({
        'Content-Type': 'application/json',
      }),
    })
      .then(res => {
        console.log('Signup processed successfully')
        this.setState({ signupmessage: 'Signup Successful!' })
        return res
      })
      .catch(error => {
        console.error('Error:', error)
        this.setState({ signupmessage: 'Signup Failed' })
      }) 

生成的mailinglist.js中的this.dynamicTemplateData=s(e,this.dynamicTemplateData)}}

unknown or a bug community enhancement

所有4条评论

你好@amlcodes

看起来 Netlify 添加了这段代码s(e,this.dynamicTemplateData)而没有定义函数s是什么。 当您删除该行时会发生什么?

最诚挚的问候,

埃尔默

我也有这个问题。
它仅在我使用templateId ,仅在 Netlify 上发生(它在我的本地机器上没有问题,节点 10.16.0)
我不知道如何删除该行并查看结果,问题仅出在 Netlify 上。

您可以尝试关闭缩小以查看根本问题是什么吗? https://github.com/netlify/netlify-lambda#debugging

实际上,很确定这将通过https://github.com/sendgrid/sendgrid-nodejs/pull/1039修复

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

mindnuts picture mindnuts  ·  41评论

r3wt picture r3wt  ·  17评论

sydneyhenrard picture sydneyhenrard  ·  17评论

francesco-clementi picture francesco-clementi  ·  26评论

thinkingserious picture thinkingserious  ·  30评论