javascript – 错误:运行firebase云功能时“无法找到模块”
作者:互联网
const functions = require('firebase-functions');
var nodemailer = require('nodemailer');
// const express=require('express');
var transporter=nodemailer.createTransport('smtps://username@gmail.com:password5@smtp.gmail.com');
exports.sendMail=functions.https.onRequest((req,res)=>{
var mailOptions={
to: 'receiver@gmail.com',
subject: 'Test Mail',
html: 'Testing with Node.js'
}
transporter.sendMail(mailOptions,function(err,response){
if(err){
res.send('Mail not sent');
}
else{
res.send('Mail sent');
}
});
});
我从Firebase应用发送邮件.我使用Firebase云功能按照我在Sending email using Firebase web app中提出的问题发送邮件.上面的代码是我的index.js文件.
这是我的package.json文件
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1",
"sendgrid": "^5.2.3"
},
"private": true
}
但是在部署代码时我遇到了错误.您是否列出了package.json依赖项中所有必需的模块?这是什么错误.怎么解决?
解决方法:
您从依赖项中丢失了nodemailer
.只需添加它……
npm install nodemailer --save
将导致(其中x.x.x是适当的版本)
"dependencies": {
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1",
"nodemailer": "^x.x.x",
"sendgrid": "^5.2.3"
}
这很可能适用于您的开发,因为您实际上已在本地或全局安装了nodemailer,但由于错误指出它在远程计算机上不存在
Cannot find module ‘nodemailer’
标签:javascript,node-js,firebase,google-cloud-functions,nodemailer 来源: https://codeday.me/bug/20190527/1162772.html