不适用于导入"/>
sendGrid 邮件不适用于导入
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: '[email protected]',
from: '[email protected]',
subject: 'Sending with Twilio 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);
以上使用需要导入sendgrid。上面的代码有效。
但是因为我使用的是 ES6 语法,我可以使用 require,我必须使用 import 来代替。
import sgMail from '@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: '[email protected]',
from: '[email protected]',
subject: 'Sending with Twilio 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);
所以,我写了这段代码,但它给出了错误,因为变量未定义(读取 setApiKey)。当我删除那条线时。它给出错误,因为变量未定义(读取发送)。
回答如下:import 语句末尾有一个右括号。我想你在转换时错过了删除它。请将其删除并重试。
更多推荐
sendGrid 邮件不适用于导入
发布评论