- 
          
- 
        Couldn't load subscription status. 
- Fork 33.6k
Description
Reading from the docs, it is not clear whether util.deprecate() should be used by userland modules or not. There is the preamble that states:
The util module is primarily designed to support the needs of Node.js' own internal APIs. However, many of the utilities are useful for application and module developers as well
Reading this, I would guess that it is ok to use util.deprecate(). The output, however, looks like this:
(node:<strange number>) DeprecationWarning <message>
The (node) prefix is indicating that the deprecation warning is coming from node itself (introduced with 9cd44bb).
If util.deprecate() is meant for internal use only, I think it would be better to remove it from the official documentation because it can be misleading for both the library authors and library users.
Just as background: I was using this method for a breaking change in webpack's loader-utils. This module is used by almost every loader, so it is very likely that it appeared at least once in the console of every webpack user. I was using this method because I think it's good to have a unified way of handling deprecations, especially in combination with the command line flags provided by node. I just wanted to stick to the community default (at least as it appeared to me).
Judging from the feedback, however, many users didn't know where the message was coming from and what to do. And I think this is also due to the unfriendly appearance of the message. It is lacking the necessary information whether if it's a problem the developer must fix or the library author. You could use --trace-deprecation, but if you never heard of util.deprecate(), you don't know that this flag exists.
Having said this, this is what I would like to change:
- Either remove util.deprecate()from the documentation or remove the(node)prefix
- In any case: The output of the warning can be improved. For example, we could add the last one or two lines of the stack trace by default to reveal which library is causing the deprecation warning. We could also add an URL to the documentation that lists all the available cli flags. I think, elm is doing an incredible good job of explaining errors/problems.