Nodemailer 在 Azure 上抛出错误

Nodemailer throws error on Azure

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

    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:

{
  "name": "passport-local-express4",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www",
    "test": "make test"
  },
  "repository": {
    "type": "git",
    "url": "git@github.com: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) 中提到的行是:

const nodemailer = require('nodemailer');

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

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

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

但是,您可以通过使用 process.version 验证应用程序中 Node.js 版本是否正确 运行,如下所示:

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);