twbs/bootstrap · error · TypeError

No method named "${config}"

Error message

No method named "${config}"

What it means

Alert's jQuery bridge (installed by defineJQueryPlugin) turns $('.alert').alert('method') into a dynamic lookup of that method on the Alert instance. jQueryInterface first verifies the string resolves on the instance, does not start with '_', and is not 'constructor'; otherwise it throws this TypeError. Alert exposes only two public methods — close and the inherited dispose — so every other string is rejected.

Source

Thrown at js/src/alert.js:67

  // Private
  _destroyElement() {
    this._element.remove()
    EventHandler.trigger(this._element, EVENT_CLOSED)
    this.dispose()
  }

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

      if (typeof config !== 'string') {
        return
      }

      if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
        throw new TypeError(`No method named "${config}"`)
      }

      data[config](this)
    })
  }
}

/**
 * Data API implementation
 */

enableDismissTrigger(Alert, 'close')

/**
 * jQuery
 */

defineJQueryPlugin(Alert)

View on GitHub (pinned to 6177d5f849)

Solutions

  1. Call one of Alert's public methods: 'close' or 'dispose'.
  2. Fix the typo — verify the name against the methods table in the Bootstrap 5.3 Alert docs.
  3. If the name is dynamic, whitelist it first: typeof instance[name] === 'function' && !name.startsWith('_') && name !== 'constructor'.
  4. Prefer the vanilla API: bootstrap.Alert.getInstance(el)?.close() degrades to undefined instead of throwing.

Example fix

// before
$('.alert').alert('disposeAll') // TypeError: No method named "disposeAll"

// after
$('.alert').alert('close')      // public methods on Alert: close | dispose
Defensive patterns

Strategy: validation

Validate before calling

function callAlertMethod(element, method) {
  const instance = bootstrap.Alert.getOrCreateInstance(element)
  const callable = typeof instance[method] === 'function' &&
    !method.startsWith('_') && method !== 'constructor'
  if (!callable) {
    console.warn(`Alert: ignoring unknown method "${method}"`)
    return
  }
  instance[method]()
}

Type guard

const ALERT_METHODS = ['close', 'dispose'] as const
type AlertMethod = (typeof ALERT_METHODS)[number]
const isAlertMethod = (m: string): m is AlertMethod =>
  (ALERT_METHODS as readonly string[]).includes(m)

Try / catch

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

Prevention

When it happens

Trigger: $('.alert').alert('show') (Alert has no show); $('.alert').alert('destory') (typo for dispose); $('.alert').alert('_element') or $('.alert').alert('constructor') (explicitly rejected by the guard); $('.alert').alert(nameFromDataset) where the method name comes from unvalidated data attributes or URL parameters.

Common situations: Copy-pasting calls written for a different component (Modal's 'show' used on an alert); simple typos; dynamic dispatch driven by user input; migrating from Bootstrap v4 where the jQuery API existed too but method names differed (v4 'destroy' became v5 'dispose').

Related errors


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