This function traps and returns any errors encountered when attempting to require a module.
Use caution when attempting to resolve a relative path or a local module. This function attempts to resolve a module from its current path. Thus, the function is unable to resolve anything which is not along its search path. For local requires, use an absolute file path.
Parameters
id: string
module id
Returns
any
module.exports of the resolved module or an error
Example
var out = tryRequire( 'beepboop' );
if ( out instanceofError ) {
console.error( out.message );
}
Wraps
require
in a try/catch block.Notes