Livewire Cannot read property '$wire' of undeinfed

If you get this error in Livewire this typically means that you are loading Alpine JS before livewire. It's a simple fix. Make sure that your livewire scripts are loading after the Alpine JS.

Here is a quick example of why you are getting this error:

<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.7.3/dist/alpine.min.js" defer></script>
@livewireScripts

It's a simple fix, you'll just need to swap the order of libraries that are loaded:

@livewireScripts
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.7.3/dist/alpine.min.js" defer></script>

If you are including Alpine inside of you main app.js, you'll need to make sure that livewire scripts are loaded before:

@livewireScripts
<script src="/assets/js/app.js"></script>

It's a pretty simple fix that will prevent this error from happening.

Back to DevDojo