I am running a Node app on Azure. It's a Web API and when I try to call it, I see this message in the Node console:
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)
I ran my whole code through eslint
and didn't find any syntax errors. It also runs fine on my local machine, but doesn't run on Azure.
The message above points to line 17 and column 23 in app.js, which is a require
:
let warehouseExport = require('./routes/warehouse-export-api');
I ran eslint
and jshint
specifically on the file referenced above, and there are no syntax errors.
What are some other ways I can get the exact location of the syntax error, and why could it be that the code fails on Azure but runs on my local machine?
What I tried:
undefined
: try { var warehouseExport = require('./routes/warehouse-export-api'); } catch (error) { console.log(error + ', line ' + error.lineNumber); }
You should check version of nodejs you have installed on Azure. Maybe it's <= 4 and it doesn't support let
keyword. Just a wild guess.
The cause of the error was that the Node version somehow got reset to 4.2.4.
When I go to Azure Portal and run node --version
, I get version 8.1.4.
However, if I console.log
the Node version inside my script, it is somehow still 4.2.4.
I will investigate why that happened and how to fix it, but for now it's clear that the bug is due to async function
not being recognized by the old Node.
Update: the package.json
file where the node version was specified got overwritten somehow, which is what caused the issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.