twbs/bootstrap · error · TypeError
No method named "${config}"
Error message
No method named "${config}" What it means
Offcanvas's jQueryInterface applies the strict guard — the method must exist on the instance, must not start with '_', and must not be 'constructor' — and calls data[config](this), passing the DOM element through (offcanvas show accepts a relatedTarget). Public methods are show, hide, toggle and dispose.
Source
Thrown at js/src/offcanvas.js:220
this.hide()
return
}
EventHandler.trigger(this._element, EVENT_HIDE_PREVENTED)
})
}
// Static
static jQueryInterface(config) {
return this.each(function () {
const data = Offcanvas.getOrCreateInstance(this, config)
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
*/
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
const target = SelectorEngine.getElementFromSelector(this)
if (['A', 'AREA'].includes(this.tagName)) {
event.preventDefault()
}
View on GitHub (pinned to 6177d5f849)
Solutions
- Use show, hide, toggle or dispose.
- Replace open/close vocabulary: open → show, close → hide.
- Never pass names starting with '_' or the literal 'constructor'.
- For dynamic calls, prefer bootstrap.Offcanvas.getOrCreateInstance(el).show().
Example fix
// before
$('#offcanvas').offcanvas('open') // TypeError: No method named "open"
// after
$('#offcanvas').offcanvas('show') // show | hide | toggle | dispose Defensive patterns
Strategy: validation
Validate before calling
function callOffcanvasMethod(element, method) {
const instance = bootstrap.Offcanvas.getOrCreateInstance(element)
const callable = typeof instance[method] === 'function' &&
!method.startsWith('_') && method !== 'constructor'
if (!callable) {
console.warn(`Offcanvas: ignoring unknown method "${method}"`)
return
}
instance[method](element)
} Type guard
const OFFCANVAS_METHODS = ['show', 'hide', 'toggle', 'dispose'] as const type OffcanvasMethod = (typeof OFFCANVAS_METHODS)[number] const isOffcanvasMethod = (m: string): m is OffcanvasMethod => (OFFCANVAS_METHODS as readonly string[]).includes(m)
Try / catch
try {
$('#offcanvas').offcanvas(method)
} catch (err) {
if (err instanceof TypeError && err.message.startsWith('No method named')) {
console.warn(`Offcanvas: unknown method "${method}"`)
} else {
throw err
}
} Prevention
- Use show/hide, not open/close, for offcanvas commands.
- This component's guard also rejects '_' names and 'constructor' outright.
- Whitelist dynamic drawer commands at the call site.
- Prefer bootstrap.Offcanvas.getOrCreateInstance(el).show().
When it happens
Trigger: $('#offcanvas').offcanvas('open') or 'close'; $('#offcanvas').offcanvas('_element') or 'constructor' (explicitly rejected); $('#offcanvas').offcanvas('display'); any guessed verb other than show, hide, toggle, dispose.
Common situations: The open/close vocabulary feels natural for offcanvas/sidebars, but Bootstrap uses show/hide; wrapper components (React/Vue offcanvas libs) forwarding wrong command strings; typos in dynamic dispatch.
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/647824cca46fac51.
Report an issue: GitHub.