nodejs模块有警告消息

时间:2012-09-13 20:32:32

标签: node.js

是否有蚂蚁方式可以使由我包含的模块引起的警告消息静音?

我喜欢这个模块,但每次调用它们的功能时,控制台都输出:

"Utf8String" type is deprecated, use "CString" instead

我正在制作一个控制台应用程序,所以我更愿意压制这个消息。

2 个答案:

答案 0 :(得分:0)

您获得的警告消息实际上来自节点,而不是模块。 但是,该模块会将警告调用为调用先前版本节点中使用的api。

我认为无论如何都要告诉节点压制记录到控制台的警告消息。

如果你确实要去除这些警告,你可以进入模块的源代码并进行查找和替换。

"Utf8String" to "CString"

我为另一个模块做了完全相同的事情,我也无法忍受这些消息。

答案 1 :(得分:0)

在这种情况下,我需要的模块需要一个模块,该模块具有使用Utf8String并为其触发错误的自定义代码。

// alias Utf8String
var utfstringwarned = false
Object.defineProperty(types, 'Utf8String', {
    enumerable: false
  , configurable: true
  , get: function () {
      if (!utfstringwarned) {
        utfstringwarned = true
        console.error('"Utf8String" type is deprecated, use "CString" instead')
      }
      return types.CString
    }
})

并在历史中写下了它

0.0.20 / 2012-06-27
===================

 - rename the `Utf8String` type to `CString` (#5)
 - make `Utf8String` an alias to `CString` and deprecated
 - more work on docs (not yet ready)

作为临时解决方案,我可能会将错误消息注释掉,或者作为更永久的解决方案,选择其他模块。