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
- Call one of Alert's public methods: 'close' or 'dispose'.
- Fix the typo — verify the name against the methods table in the Bootstrap 5.3 Alert docs.
- If the name is dynamic, whitelist it first: typeof instance[name] === 'function' && !name.startsWith('_') && name !== 'constructor'.
- 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
- Whitelist method names before dispatch; never interpolate raw input into $(...).alert(name).
- Learn the v5 vocabulary: close/dispose here (not open/close/destroy).
- Prefer bootstrap.Alert.getInstance(el)?.close() — undefined instead of a throw.
- Names starting with '_' and 'constructor' are always rejected.
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
- No method named "${config}"
- No method named "${config}"
- No method named "${config}"
- No method named "${config}"
- No method named "${config}"
AI-assisted analysis of twbs/bootstrap@6177d5f849 (2026-08-22).
Data as JSON: /api/errors/99ad6c0802c9871b.
Report an issue: GitHub.