jQuery autoloading apparently not working
See original GitHub issue- Laravel Mix Version: 0.9.2
- Node Version (
node -v
): v6.9.5 - NPM Version (
npm -v
): 3.10.10 - OS: VM Homestead
Description:
I can’t load jQuery using laravel-mix. I’ve added this snippet to webpack.mix.js
:
mix.autoload({
jquery: ['$', 'window.jQuery']
});
as shown here: https://github.com/JeffreyWay/laravel-mix/blob/master/docs/autoloading.md
In any blade template, I can add something like this
<script>
$(document).ready(function () {
alert("jQuery loaded");
});
</script>
But the $ is not recognised (browser error: ReferenceError: Can't find variable: $
)
In case it was an issue with the setup of my project, I’ve created a new laravel project from scratch, and I have the same issue.
Steps To Reproduce:
laravel new testsite
edit welcome.blade.php
and add the script snippet mentioned above
npm run dev
open testsite, browser shows error mentioned above
Issue Analytics
- State:
- Created 6 years ago
- Comments:15
Top Results From Across the Web
jQuery autoloading apparently not working · Issue #646 - GitHub
In my project, the issue comes from the loading order: I load <script src="/js/app.js"></script> after yielding the content - @yield('content') ...
Read more >Does laravel 6 auto-load jquery? Getting uncaught type error
So I don't know what's going on. Theoretically it's being double loaded but if i comment it out, it's obviously not loaded from...
Read more >jQuery UI libraries are loading too much CSS that needs to be ...
The problem is that we auto-load the default theme of jQuery UI, which is then applied to all elements using jQuery UI's CSS...
Read more >Lightbox is causing other jQuery to malfunction - SitePoint
If that doesn't work, try running jQuery in compatibility mode. Prototype overwrites the $ function, which causes problems when using both ...
Read more >Other events not working after load - jQuery Forum
Hello, I am trying to add a div to my container on click and inside the div - I have tabs and other...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Be careful with script
defer
attribute also. That will make your autoloaded jQuery unavailable in blade files@MladenJanjetovic the whole setup seems confusing to me as a Laravel newcomer, but the way I finally made it work correctly was:
That way, $ is available later on when you require it in a blade template.