2017-09-26 19 views
1

我正在Azure上運行一個Node應用程序。這是一個Web API,當我嘗試調用它,我看到控制檯節點此消息:我在Node.JS中得到一個SyntaxError,但我無法從日誌消息中找出該錯誤的來源

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

我跑eslintjshint專門對上面提到的文件中,並且不存在語法錯誤。

有什麼其他方法可以獲取語法錯誤的確切位置,以及爲什麼代碼在Azure上失敗,但在本地計算機上運行?

我的嘗試:

  • 裹在try-catch代碼和搶行號 - 它顯示了undefined

try { var warehouseExport = require('./routes/warehouse-export-api'); } catch (error) { console.log(error + ', line ' + error.lineNumber); }

+0

@RobertRowntree它沒有工作,因爲我剛剛添加這個新文件。沒有額外的構建步驟,該應用程序非常簡單,我以前只是將整個目錄FTP到服務器,然後完成。 – K48

+0

@ K48你有沒有試過''catch'裏面的console.log(error.stack)'?你提供的跟蹤(我猜Azure所報告的)似乎會錯過通常在'SyntaxError'情況下顯示的引導行。 –

回答

2

您應該檢查的NodeJS的版本,已經安裝在Azure上。也許它是< = 4,它不支持let關鍵字。只是一個瘋狂的猜測。

+0

好猜,但是'node --version'顯示'v8.1.4' – K48

+0

原來你是對的!請參閱下面我的詳細答案 – K48

1

錯誤的原因是Node版本以某種方式重置爲4.2.4。

當我轉到Azure門戶並運行node --version時,獲得版本8.1.4。

但是,如果我的console.log節點版本在我的腳本中,它仍然是4.2.4。

我會調查爲什麼發生了,以及如何解決它,但現在很明顯,該錯誤是由於async function不被舊節點識別。

更新:指定節點版本的package.json文件以某種方式被覆蓋,這是導致問題的原因。

相關問題