Migration from Alpine v2 to v3
Learn the key changes when upgrading to Alpine 3.
Upgrading to Alpine 3
Alpine 3 was a major rewrite that reduced the core size by 85% while improving performance and simplifying the API. Most of the concepts from v2 remain, but there are a few breaking changes you need to know.
Key Changes
- $el now refers to the root element of the component (the element with
x-data), not the element where the expression is evaluated. Use$refsfor child elements. - x-spread has been replaced by
x-bindwith an object argument or byAlpine.bind(). - Alpine.data() must be called before
Alpine.start(). Use thealpine:initevent to register your data factories. - Custom directives and magics are now registered using
Alpine.directive()andAlpine.magic()instead ofAlpine.directive()andAlpine.magic()(same names, slightly different signatures). - The
initmethod insidex-datais now the recommended way to run setup code, replacing the oldx-initinline functions. - Alpine no longer depends on
@popperjs/coreinternally; anchor positioning is now a separate plugin.
Quick Migration Steps
- Update the CDN link or npm package to v3.
- Replace
x-spreadwithx-bindorAlpine.bind(). - Move
Alpine.data()calls beforeAlpine.start(). - Adjust any custom directives or magics to the new API.
- Test all components, especially those relying on
$el.
Resources
The Official Upgrade Guide provides a comprehensive, step‑by‑step migration path. Most v2 markup works with minimal changes.
💡 Tip
Run your test suite (if you have one) after upgrading to catch any unexpected behaviour.
Helpful? Share this page!↑ Back to top