Nodemailer在Azure上引发错误

Nodemailer在Azure上引发错误

本文介绍了Nodemailer在Azure上引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在已部署在Azure上的NodeJS应用程序中使用nodemailer程序包.如果我在本地主机上执行该应用程序,则一切正常.如果我在Azure上执行它,则会引发以下错误:

I'm trying to use the nodemailer package in my NodeJS app, which I have deployed on Azure. If I execute the app on my localhost everything works fine. If I execute it on Azure it throws the following error:

    Thu Jan 25 2018 09:03:31 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:
SyntaxError: Unexpected token ...
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (D:\home\site\wwwroot\node_modules\nodemailer\lib\nodemailer.js:3:16)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (D:\home\site\wwwroot\api\apiAccount.js:5:20)
    at Module._compile (module.js:409:26)

这是我的package.json:

This is my package.json:

{
  "name": "passport-local-express4",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www",
    "test": "make test"
  },
  "repository": {
    "type": "git",
    "url": "[email protected]:mjhea0/passport-local-express4.git"
  },
  "engines": {
    "node": "8.9.0"
  },
  "dependencies": {
    "async": "^2.6.0",
    "azure-storage": "^2.6.0",
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.17.2",
    "chai": "^1.8.1",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.4.3",
    "debug": "^2.6.8",
    "express": "^4.15.3",
    "express-fileupload": "^0.3.0",
    "express-session": "^1.10.1",
    "jade": "^1.11.0",
    "mocha": "^1.14.0",
    "mongoose": "^4.10.6",
    "morgan": "^1.8.2",
    "node-cache": "^4.1.1",
    "nodemailer": "*",
    "passport": "^0.2.2",
    "passport-local": "^1.0.0",
    "passport-local-mongoose": "^1.3.0",
    "serve-favicon": "^2.4.3",
    "should": "^2.1.1",
    "xoauth2": "^1.2.0"
  }
}

如果我导航到Azure上的node_modules目录,则nodemailer是一个文件夹,并且所有必需的代码都在其中.如果我在Kudu控制台上运行node -v,则NodeJS版本为8.9.0.错误消息(apiAccount5:20)中提到的行是:

If I navigate to thenode_modules directory on Azure, nodemailer is a folder and all the necessary code is in there. If I run node -v on the Kudu console the NodeJS version is 8.9.0. The line, which is mentioned in the error message (apiAccount5:20) is:

const nodemailer = require('nodemailer');

如果我尝试在Kudu控制台中运行node app.js,则不会引发任何错误.有什么想法吗?

If I try to run node app.js in the Kudu console, there are no errors thrown.Any ideas?

推荐答案

确保iisnode.yml文件中包含以下行:

Make sure you have the following line in iisnode.yml file:

nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\8.9.0\node.exe"

但是,您可以使用 process.version 像这样:

However, you can verify the correct Node.js version running in your application by using process.version like this:

var http = require('http');
http.createServer(function(req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('Hello from Azure running node version: ' + process.version + '</br>');
}).listen(process.env.PORT || 3000);

这篇关于Nodemailer在Azure上引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 08:09