gpt4 book ai didi

node.js - Nodemailer 在 Azure 上抛出错误

转载 作者:行者123 更新时间:2023-12-03 05:50:25 25 4
gpt4 key购买 nike

我正在尝试在我的 NodeJS 应用程序中使用 nodemailer 包,该应用程序已部署在 Azure 上。如果我在本地主机上执行该应用程序,一切正常。如果我在 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": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caada3be8aada3bea2bfa8e4a9a5a7" rel="noreferrer noopener nofollow">[email protected]</a>: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\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);

关于node.js - Nodemailer 在 Azure 上抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48439922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com