Context:
- I am using Laravel 8 with Livewire.
- Alpine.js is installed via npm in my package.json:
"devDependencies": {
"alpinejs": "^3.15.2"
}
I am not using a CDN for Alpine.js. My layout includes the CSS and JS like this:
<!-- Layout config JS -->
<script src="{{ URL::asset('build/js/layout.js') }}"></script>
<!-- Bootstrap CSS -->
<link href="{{ URL::asset('build/css/bootstrap.min.css') }}" rel="stylesheet" type="text/css" />
<!-- Icons CSS -->
<link href="{{ URL::asset('build/css/icons.min.css') }}" rel="stylesheet" type="text/css" />
Problem: Whenever I try to use x-data or other Alpine.js directives in my Livewire components, I get the Alpine is not defined error.
What I tried:
- Checked if alpinejs is installed via npm.
- Verified that node_modules is present.
- Tried including Alpine.js via CDN (worked, but I want to use npm).
Questions:
- How can I properly load Alpine.js when using Laravel Livewire without a CDN?
- Do I need to compile my assets with Laravel Mix / Vite to make Alpine available?
@livewireScriptsin your layout to manually/force the script to load?