fynjs API
    Preparing search index...

    Type Alias OptionalImportOpts

    Options for calling an optional import

    type OptionalImportOpts = {
        default?: unknown;
        fail?: (err: Error) => unknown;
        log?: LogFunction;
        message?: true | string;
        meta?: ImportMetaLike;
        notExported?: NotExportedHandling;
        notFound?: (err: Error) => unknown;
    }
    Index
    default?: unknown

    The value to return if the module was not found but notFound is not provided.

    fail?: (err: Error) => unknown

    fail is a function. If the module resolved but importing it threw -- for example it contains a syntax error, throws at module scope, or one of its dependencies is missing -- then:

    • call fail if it's provided
    • else rethrow the error

    Type Declaration

      • (err: Error): unknown
      • Parameters

        • err: Error

          the error from importing the module

        Returns unknown

    This is a separate callback from notFound so a genuinely broken optional dependency is never silently swallowed as if it were simply absent.

    function to log the module not found message, default log function uses console.log

    message?: true | string

    Tell optional import to log a message if the module is not found.

    • note: it doesn't log if the module was found but failed to import

    This field can have these values:

    1. true - log with default message
    2. string - a string to prepend to the message being logged

    meta is the import.meta from the caller's context.

    If not provided, then use the one received when creating the optional import function.

    notExported?: NotExportedHandling

    How to treat a package that is installed but does not export the requested subpath.

    "notFound"

    notFound?: (err: Error) => unknown

    notFound is a function. If the specifier could not be resolved, then:

    • call notFound if it's provided
    • else return the default value.

    Type Declaration

      • (err: Error): unknown
      • Parameters

        • err: Error

          the resolve error

        Returns unknown