You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tree‑shaking removes DOM‑initializing side‑effects, breaking element.bootstrapToggle() when imported via bundlers #334
When bootstrap5-toggle is used via an ES module/bundler import instead of a CDN script tag, the DOM‑initializing side‑effect that registers bootstrapToggle on HTMLInputElement.prototype is being removed by tree‑shaking. As a result, code that previously worked, such as calling element.bootstrapToggle() (or this.$refs.toggle.bootstrapToggle() in Vue), now throws:
TypeError: element.bootstrapToggle is not a function
The workaround of directly instantiating new BootstrapToggle(element) still works, which indicates that the core class is present but the prototype patch is not being executed in bundled builds.
Steps to Reproduce
Install bootstrap5-toggle via npm.
Import the full bundle inside an ESM/bundler environment (Vite, Webpack, Rollup, Vue CLI, etc.):
Render a component containing an input toggle, for example in Vue:
<inputref="toggle" data-toggle="toggle">
After mount, attempt to call:
this.$refs.toggle.bootstrapToggle();
Observe that the method is missing and the following error is thrown:
TypeError: this.$refs.toggle.bootstrapToggle is not a function
Expected Behavior
When importing the full bundle, the library should always execute its DOM‑initializing side‑effects. As a result, the bootstrapToggle method should be registered on HTMLInputElement.prototype, allowing code such as:
element.bootstrapToggle();
to work reliably in any environment (CDN, ESM, bundlers) without requiring manual instantiation or additional configuration.
Actual Behavior
Instead of registering the bootstrapToggle method on HTMLInputElement.prototype, the imported bundle is tree‑shaken and the DOM‑initializing side‑effect is removed. As a result, the element received by the framework (e.g., Vue) is a plain HTMLElement without the expected method. Calling:
this.$refs.toggle.bootstrapToggle();
throws:
TypeError: this.$refs.toggle.bootstrapToggle is not a function
The class BootstrapToggle is still available, and manual instantiation works, which confirms that only the prototype‑patching side‑effect is being eliminated by the bundler.
Severity
Severe
Bootstrap 5 Toggle Version
5.4.0
Bootstrap version
^5.0.0
Other
The issue only appears in ESM/bundler environments (Vite, Webpack, Rollup, Vue CLI).
It does not occur when loading the library via CDN because the IIFE is always executed.
Bug Report Checklist
Confirm that you agree to follow the project's code of conduct.
Confirm that you have reviewed open and rejected anomalies and have not found the reported anomaly.
Activity
github-actions commentedon Jun 28, 2026
Hi! 👋
Thanks for your issue. You are helping to improve Bootstrap 5 toggle.
palcarazm commentedon Jun 28, 2026
Hi @danports
I've released v5.4.1 with
sideEffectsconfiguration. Thanks for your help!