2017-04-06 33 views
0

我正在創建幾個npm腳本,並且我發現在一個失敗的情況下會返回一個錯誤對象。我想在控制檯中顯示該對象的格式化屬性。那可能嗎?如何僅在npm腳本中顯示格式錯誤?

目前我在控制檯中看到:

{ 
    "status": 1, 
    "file": "stylesheets/main.scss", 
    "line": 6, 
    "column": 3, 
    "message": "property \"adfasdagdajhgdaj\" must be followed by a ':'", 
    "formatted": "Error: property \"adfasdagdajhgdaj\" must be followed by a ':'\n  on line 6 of assets/stylesheets/main.scss\n>> adfasdagdajhgdaj\n --^\n" 
} 

我想只有有:

"Error: property \"adfasdagdajhgdaj\" must be followed by a ':'\n  on line 6 of assets/stylesheets/main.scss\n>> adfasdagdajhgdaj\n --^\n" 

感謝

回答

0

你應該使用try catch塊和日誌只有格式化

try { 
    //Do cool stuff 
}catch (e) { 
    console.log(e.formatted); 
} 
+0

你是否建議把一個try {} catch()放入package.json中? – McSas

+0

哦,我誤讀了,我不知道該怎麼做,對不起 – Keylies