我有一個箭頭的功能,但是當我把它,說明它不是一個函數。箭頭功能不起作用?
TypeError: callback is not a function
module.exports = app => {
const mailer = nodemailer.createTransport(sgTransport(options));
return {
send: (config, callback) => {
if(config.content && config.to && config.subject) {
let email = {
from: '[email protected]',
to: config.to,
subject: config.subject,
text: 'config.subject'
};
const path = "./emails/" + config.template + ".html";
let pageHtml = '';
fs.readFile(path, (err, data) => {
if (err) throw err;
pageHtml = data.toString();
email.html = pageHtml.replace("[EMAIL.CONTENT]", email.content);
mailer.sendMail(email, (err, res) => {
if (err) {
console.log("Erro ao enviar email.")
}
if (typeof callback == "function") {
return callback(res);
}
});
});
}
else {
console.log("Necessário passar um config válido.");
}
}
};
};
mail.send(email, (callback) => {
console.log(typeof callback);
// console.log(callback);
});
我是新箭頭的功能,也許這可能是問題。但是我已經搜索並找不到問題。
錯誤是由哪條線產生的? –
*最小*示例? http://stackoverflow.com/help/mcve –
@m_callens /home/daniel/Documentos/telemonitoramentonode/api-fullmonitoramento/node_modules/mongodb/lib/utils.js:98 process.nextTick(function(){throw err; }); 該行是錯誤將無濟於事,因爲它來自nodejs事件循環(我認爲)。 –