twbs/bootstrap · error · TypeError

No method named "${config}"

Error message

No method named "${config}"

What it means

Toast's jQueryInterface only acts on string arguments and uses the simple undefined guard, then calls data[config](this). Public methods are show, hide and dispose (isShown also exists on the instance). Non-string arguments such as numbers or objects do not throw here — they silently just create the instance.

Source

Thrown at js/src/toast.js:203

    EventHandler.on(this._element, EVENT_MOUSEOVER, event => this._onInteraction(event, true))
    EventHandler.on(this._element, EVENT_MOUSEOUT, event => this._onInteraction(event, false))
    EventHandler.on(this._element, EVENT_FOCUSIN, event => this._onInteraction(event, true))
    EventHandler.on(this._element, EVENT_FOCUSOUT, event => this._onInteraction(event, false))
  }

  _clearTimeout() {
    clearTimeout(this._timeout)
    this._timeout = null
  }

  // Static
  static jQueryInterface(config) {
    return this.each(function () {
      const data = Toast.getOrCreateInstance(this, config)

      if (typeof config === 'string') {
        if (typeof data[config] === 'undefined') {
          throw new TypeError(`No method named "${config}"`)
        }

        data[config](this)
      }
    })
  }
}

/**
 * Data API implementation
 */

enableDismissTrigger(Toast)

/**
 * jQuery
 */

View on GitHub (pinned to 6177d5f849)

Solutions

  1. Use show, hide or dispose.
  2. Replace 'destroy' with 'dispose' for v5.
  3. For dynamic toast commands, whitelist the three names before dispatch.
  4. Prefer the vanilla API: bootstrap.Toast.getOrCreateInstance(el).show().

Example fix

// before
$('#toast').toast('display') // TypeError: No method named "display"

// after
$('#toast').toast('show') // show | hide | dispose
Defensive patterns

Strategy: validation

Validate before calling

function callToastMethod(element, method) {
  const instance = bootstrap.Toast.getOrCreateInstance(element)
  if (typeof instance[method] !== 'function') {
    console.warn(`Toast: ignoring unknown method "${method}"`)
    return
  }
  instance[method](element)
}

Type guard

const TOAST_METHODS = ['show', 'hide', 'dispose'] as const
type ToastMethod = (typeof TOAST_METHODS)[number]
const isToastMethod = (m: string): m is ToastMethod =>
  (TOAST_METHODS as readonly string[]).includes(m)

Try / catch

try {
  $('#toast').toast(method)
} catch (err) {
  if (err instanceof TypeError && err.message.startsWith('No method named')) {
    console.warn(`Toast: unknown method "${method}"`)
  } else {
    throw err
  }
}

Prevention

When it happens

Trigger: $('#toast').toast('display'); $('#toast').toast('remove'); $('#toast').toast('destroy') (v4 name → v5 dispose); $('#toast').toast('hideNow').

Common situations: Notification code written with remove/dismiss vocabulary; v4→v5 migrations ('destroy' → 'dispose'); toast managers forwarding arbitrary command strings.

Related errors


AI-assisted analysis of twbs/bootstrap@6177d5f849 (2026-08-22). Data as JSON: /api/errors/663c78e7c1444a5e. Report an issue: GitHub.