如何只显示npm脚本中的格式化错误?

时间:2017-04-06 15:42:34

标签: node.js npm sass node-sass

我正在创建几个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"

由于

1 个答案:

答案 0 :(得分:0)

您应该使用try catch块并仅记录格式化的

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