我正在 Azure 上运行 Node 应用程序。它是一个 Web API,当我尝试调用它时,我在 Node 控制台中看到此消息:
Application has thrown an uncaught exception and is terminated:
SyntaxError: Unexpected token (
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (D:\home\site\wwwroot\app.js:17:23)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
我通过 eslint 运行了整个代码,没有发现任何语法错误。它在我的本地计算机上也运行良好,但不能在 Azure 上运行。
上面的消息指向app.js中的第17行和第23列,这是一个require
:
let warehouseExport = require('./routes/warehouse-export-api');
我专门对上面引用的文件运行了 eslint 和 jshint ,并且没有语法错误。
还有哪些其他方法可以获取语法错误的确切位置?为什么代码在 Azure 上失败但在我的本地计算机上运行?
我尝试过的:
- 包裹在 try-catch 中并获取行号 - 它显示
未定义
:
尝试 {
varwarehouseExport = require('./routes/warehouse-export-api');
} 捕获(错误){
console.log(错误 + ', 行 ' + error.lineNumber);
}
最佳答案
您应该检查 Azure 上安装的 Nodejs 版本。也许它是 <= 4 并且不支持 let
关键字。只是一个疯狂的猜测。
关于javascript - 我在 Node.JS 中收到 SyntaxError,但我无法从日志消息中找出该错误的根源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46420215/