我正在尝试在我在Azure上部署的NodeJS应用中使用nodemailer
包。如果我在我的localhost上执行应用程序一切正常。如果我在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
,则不会抛出任何错误。
有什么想法吗?
答案 0 :(得分:2)
确保iisnode.yml
文件中包含以下行:
nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\8.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);