Would it be a good idea to add an install method that performs asyncHook.createHook() and modifies Error.prepareStackTrace (through stack-chain) instead of automatically doing it when the module is required?
It can already be done right now by conditionally calling require() but this might be problematic when using ES modules and import (until dynamic imports become more supported).
Also it goes against the assumption some users may have, that when they require() a module, it only defines functions and constants and does not perform significant logic.
A good compromise to support both behaviors is often to add a register.js file that performs the modification automatically, and offer an install method in the main export.
Would it be a good idea to add an
install
method that performsasyncHook.createHook()
and modifiesError.prepareStackTrace
(throughstack-chain
) instead of automatically doing it when the module is required?It can already be done right now by conditionally calling
require()
but this might be problematic when using ES modules andimport
(until dynamic imports become more supported).Also it goes against the assumption some users may have, that when they
require()
a module, it only defines functions and constants and does not perform significant logic.A good compromise to support both behaviors is often to add a
register.js
file that performs the modification automatically, and offer aninstall
method in the main export.There could also be an
uninstall
method.