【问题标题】:Heroku issue with NodeMailerNodeMailer 的 Heroku 问题
【发布时间】:2015-02-18 09:16:40
【问题描述】:

我在 Heroku 上遇到了 Nodemailer 问题,非常感谢您的帮助。

以前我的应用程序版本在 Heroku 上运行时没有问题,当我回滚到该版本时,它仍然可以正常运行。在最新版本的应用程序中,我没有对访问 Nodemailer 的代码进行任何更改,所以这对我来说真的没有意义。

nodemailer版本为:0.6.5

这是日志消息:

2015-02-18T04:29:57.730815+00:00 app[web.2]: POST /employer/53f44e3df4f8150200554eb7/job/ 200 32ms - 581b
2015-02-18T04:29:58.045066+00:00 app[web.2]: /app/node_modules/nodemailer/node_modules/simplesmtp/lib/client.js:918
2015-02-18T04:29:58.045069+00:00 app[web.2]:     this._xoauth2.reconnectCount = 0;
2015-02-18T04:29:58.045070+00:00 app[web.2]:                                  ^
2015-02-18T04:29:58.041300+00:00 app[web.2]: Exit callback being invoked
2015-02-18T04:29:58.045072+00:00 app[web.2]: TypeError: Cannot assign to read only property 'reconnectCount' of false
2015-02-18T04:29:58.045073+00:00 app[web.2]:     at SMTPClient._actionAUTHComplete (/app/node_modules/nodemailer/node_modules/simplesmtp/lib/client.js:918:34)
2015-02-18T04:29:58.045075+00:00 app[web.2]:     at SMTPClient._onData (/app/node_modules/nodemailer/node_modules/simplesmtp/lib/client.js:352:29)
2015-02-18T04:29:58.045076+00:00 app[web.2]:     at TLSSocket.emit (events.js:107:17)
2015-02-18T04:29:58.045078+00:00 app[web.2]:     at readableAddChunk (_stream_readable.js:163:16)
2015-02-18T04:29:58.045079+00:00 app[web.2]:     at TLSSocket.Readable.push (_stream_readable.js:126:10)
2015-02-18T04:29:58.045080+00:00 app[web.2]:     at TCP.onread (net.js:529:20)
2015-02-18T04:29:58.769185+00:00 heroku[web.2]: Process exited with status 1
2015-02-18T04:29:58.780771+00:00 heroku[web.2]: State changed from up to crashed
2015-02-18T04:29:58.780771+00:00 heroku[web.2]: State changed from crashed to starting
2015-02-18T04:30:00.371578+00:00 heroku[web.2]: Starting process with command `node app.js`
2015-02-18T04:30:01.904015+00:00 app[web.2]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2015-02-18T04:30:01.904115+00:00 app[web.2]: Recommending WEB_CONCURRENCY=1
2015-02-18T04:30:02.288471+00:00 app[web.2]: Failed to load c++ bson extension, using pure JS version
2015-02-18T04:30:02.652326+00:00 app[web.2]: Started in PROD mode
2015-02-18T04:30:02.815284+00:00 app[web.2]: Express server listening on port 9622
2015-02-18T04:30:03.291115+00:00 heroku[web.2]: State changed from starting to up

我们可以看到它在“client.js”的第 918 行失败,错误为:

TypeError:无法分配给 false 的只读属性“reconnectCount”。

为什么要尝试将“false”分配给“reconnectCount”?

我的代码很简单:

app.locals.smtpTransport = nodemailer.createTransport('SMTP', { 服务:'Gmail', 授权:{ 用户:“example@gmail.com”, 通过:“pass123” } }); 然后我使用代码发送邮件,如:

req.app.locals.smtpTransport.sendMail(......

此代码适用于我的 Heroku 暂存实例,因此对我来说没有意义。

我已经记录了 Heroku 的支持请求,您可以提供的任何指导我都会传递给他们。

非常感谢您的帮助。

【问题讨论】:

    标签: node.js heroku nodemailer


    【解决方案1】:

    我刚刚从 Nodemailer 收到以下回复:

    您可能正在 iojs 中运行 Nodemailer。节点 0.12 和 iojs 仅支持最新版本的 Nodemailer,因此您应该自己升级或修复第 918 行,如下所示:

    if(this._xoauth2){
        this._xoauth2.reconnectCount = 0;
    }
    

    在 ES5 中允许将属性设置为布尔值,但 iojs 运行 ES6 并尝试在 ES6 严格模式下设置属性会引发错误。

    我想我已经通过将我的包文件中的 node.js 版本显式设置为使用 ES5 的旧版本来解决此问题。

    这解决了我的问题。经验教训是始终在包文件中设置 nodejs 版本,否则 Heroku 使用最新版本,它可能与您的模块不兼容。

    非常感谢 Nodemailer,他们非常迅速地回复了我,并得到了很好的回应。

    希望这对其他人有帮助。

    谢谢。

    【讨论】:

    • 这对于安装 Ghost 博客平台的开发人员很有用。将 Nodejs 升级到 0.12 版后,假设您使用的是 0.4 之前的 Ghost 版本,您将在以下文件的此行号处收到此错误,具体取决于您的 Ghost 版本号和 nodemailer 版本:ghost/node_modules/nodemailer/node_modules/simplesmtp/lib/client.js:828。我相应地编辑了这一行,我的 pre v.0.4 Ghost 博客现在可以使用 Nodejs v.0.12 发送电子邮件。
    • 升级到最新版本后,这对我来说非常有效。
    【解决方案2】:

    我在 ubuntu 安装上使用流星,升级到 Node.js v12.0 并安装 Meteor 的帐户密码模块后,我遇到了类似的错误。

    事实证明,由于 Meteor 尚未开始开发与 Node.js v12.0 的兼容性,因此在我的服务器上随 Node 一起安装的新二进制文件与我的部署捆绑的二进制文件不兼容,因此我遇到了类似的错误。在这种情况下,问题不在于 Nodemailer,而在于 simplesmtp。

    按照here 的建议,解决方案是删除捆绑版本并使用 npm 安装服务器本地版本。

    所以在我的部署脚本中,我在构建捆绑包后添加了以下几行。

    cd bundle/programs/server/
    sudo rm -R ./npm/npm-bcrypt/node_modules/bcrypt
    sudo npm install bcrypt
    sudo rm -R ./npm/email/node_modules/simplesmtp
    sudo npm install simplesmtp
    

    这比修改源代码更容易,尤其是在您有脚本部署的情况下。

    【讨论】:

    • 请注意,在 Meteor 1.3(可能更高版本)中,文件结构已更改,email 现在位于 bundle/programs/server/npm/node_modules/meteor/email
    • npm-bcrypt 也已被移动。虽然它很容易找到和删除,但我不知道应该在哪里重新安装它...
    猜你喜欢
    • 1970-01-01
    • 2018-08-27
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多