Javascript 使用sendGrid api时未定义要求

Javascript 使用sendGrid api时未定义要求,javascript,node.js,firebase,sendgrid,Javascript,Node.js,Firebase,Sendgrid,我在执行代码时不断收到“requirenotdefined”错误消息。有人知道为什么会这样吗 SENDGRID_API_KEY = // "api key here"; const sgMail = require("@sendgrid/mail"); sgMail.setApiKey(process.env.SENDGRID_API_KEY); const msg = { to: "test.account@gmail.co

我在执行代码时不断收到“requirenotdefined”错误消息。有人知道为什么会这样吗

    SENDGRID_API_KEY =
//   "api key here";

const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_API_KEY);

const msg = {
  to: "test.account@gmail.com", // Change to your recipient
  from: "test2.account@gmail.com", // Change to your verified sender
  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)
  .then(() => {
    console.log("Email sent");
  })
  .catch((error) => {
    console.error(error);
  });
SENDGRID\u API\u密钥=
//“api密钥在此”;
const sgMail=require(@sendgrid/mail”);
sgMail.setApiKey(process.env.SENDGRID\u API\u KEY);
常数msg={
到:“测试。account@gmail.com“,//更改为您的收件人
发自:“test2。account@gmail.com“,//更改为您的已验证发件人
主题:“使用SendGrid发送很有趣”,
text:“在任何地方都可以轻松操作,即使使用Node.js”,
html:“并且在任何地方都可以轻松操作,即使使用Node.js”,
};
邮政总局
.send(msg)
.然后(()=>{
控制台日志(“已发送电子邮件”);
})
.catch((错误)=>{
控制台错误(error);
});

您使用哪个节点版本?嘿,我使用的是14.14.0版。您在本地使用
npm start
时是否有错误?嘿,我在运行npm start时遇到此错误:npm ERR!缺少脚本:启动npm错误!此运行的完整日志可在以下位置找到:npm ERR/Users/tategraham/.npm/_logs/2020-11-09T02_03_02_011Z-debug.log您安装了npm吗?