Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/try-require/docs/types/index.d"

Index

Functions

Functions

Export assignment tryRequire

  • tryRequire(id: string): any
  • Wraps require in a try/catch block.

    Notes

    • 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 instanceof Error ) {
        console.error( out.message );
    }