Laravel Mix Uncaught ReferenceError: $ is not defined

I’ve searched and searched and I can’t find the answer to my problem on SO. So here’s my issue. I’m trying to load jQuery Globally using Laravel Mix. I’ve tried modifying all sorts of files, and nothing seems to be working… I’m still getting the “$ is not defined” error.

Here’s my code.

Bootstrap.js

window._ = require('lodash');
window.Popper = require('popper.js').default;

try {
    window.$ = window.jQuery = require('jquery');

    require('bootstrap');
} catch (e) {}

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';


let token = document.head.querySelector('meta[name="csrf-token"]');

if (token) {
    window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}

webpack.mix.js

mix.js('resources/assets/js/app.js', 'public/js')
   .js('resources/assets/js/select2.min.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
   .sass('resources/assets/sass/admin/app.scss', 'public/css/admin')
   .copy('resources/assets/css/fontawesome.css', 'public/css')
   .copy('resources/assets/css/select2.min.css', 'public/css')
   .copy('resources/assets/webfonts', 'public/webfonts')
   .copy('resources/assets/js/tinymce', 'public/js/tinymce');

mix.browserSync('http://localhost:8000');

Error I’m getting:

Error Screenshot

Uncaught ReferenceError: $ is not defined

Code on inside of create.blade.php in the @section(‘scripts’)

<script>
   $(function(){
        alert();
    });
</script>
{{-- Tiny MCE --}}
<script src="/js/tinymce/tinymce.min.js"></script>
<script>
    tinymce.init({
        selector:'textarea',
        plugins: 'link',
        menubar: false,
        branding: false,
        resize: false,
        statusbar: false,
        force_br_newlines : false,
        force_p_newlines : false,
        forced_root_block : '',
        toolbar:    ['undo redo | cut copy paste | removeformat',
                    'bold italic underline | link | outdent indent | alignleft aligncenter alignright alignjustify alignnone',],
    });
</script>

{{-- Image Javascript --}}
<script type="text/javascript">
    $(function() {

        // We can attach the `fileselect` event to all file inputs on the page
        $(document).on('change', ':file', function() {
            var input = $(this),
            numFiles = input.get(0).files ? input.get(0).files.length : 1,
            label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
            input.trigger('fileselect', [numFiles, label]);
        });

        // We can watch for our custom `fileselect` event like this
        $(document).ready( function() {
            $(':file').on('fileselect', function(event, numFiles, label) {

            var input = $(this).parents('.input-group').find(':text'),
            log = numFiles > 1 ? numFiles + ' files selected' : label;

            if( input.length ) {
                input.val(log);
            } else {
                if( log ) alert(log);
            }

            });
        });

    });
</script>

AND finally my layout file

<!-- Scripts -->
        <script src="{{ asset('js/app.js') }}" defer></script>

        {{-- Page Specific Scripts --}}
        @yield('scripts')

    </body>

What am I doing wrong?!?!?

Console.log(e) returns nothing… which means jquery should be loading correctly but isn’t.

this is the app.js file

Still giving same error

210 thoughts on “Laravel Mix Uncaught ReferenceError: $ is not defined”

  1. Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but other than that, this is excellent blog. A fantastic read. I’ll definitely be back.

    Reply
  2. Heya! I realize this is kind of off-topic however I needed to ask.
    Does managing a well-established website like yours require
    a lot of work? I am completely new to writing a blog but I do write
    in my journal on a daily basis. I’d like to start a blog
    so I will be able to share my experience and feelings online.
    Please let me know if you have any suggestions or tips for brand new
    aspiring bloggers. Thankyou!

    Reply
  3. I’m not sure exactly why but this blog is loading very slow for
    me. Is anyone else having this problem or is it a issue on my end?
    I’ll check back later and see if the problem still exists.

    Reply
  4. Amazing blog! Do you have any hints for aspiring writers?

    I’m hoping to start my own blog soon but I’m a little lost
    on everything. Would you advise starting with a free platform like WordPress or go for
    a paid option? There are so many choices out there that I’m completely overwhelmed ..
    Any ideas? Many thanks!

    Reply
  5. Pingback: use of ivermectin
  6. Right here is the perfect blog for anybody who wants to understand this topic.
    You realize a whole lot its almost tough to argue with you (not that I personally will
    need to…HaHa). You definitely put a new spin on a topic that has been written about for many
    years. Great stuff, just excellent! scoliosis surgery https://0401mm.tumblr.com/ scoliosis surgery

    Reply
  7. Pingback: deltasone for sale
  8. Pingback: gay dating romeo
  9. Pingback: ivermectin 5
  10. Pingback: ivermectin for aml
  11. Write more, thats all I have to say. Literally, it seems
    as though you relied on the video to make your point. You obviously know what youre
    talking about, why waste your intelligence on just
    posting videos to your site when you could be giving us something informative to read?

    Reply
  12. Pingback: street sex games
  13. My coder is trying to persuade me to move to .net from
    PHP. I have always disliked the idea because of the expenses.

    But he’s tryiong none the less. I’ve been using WordPress
    on several websites for about a year and am anxious about switching to another platform.

    I have heard excellent things about blogengine.net.
    Is there a way I can transfer all my wordpress posts into it?
    Any help would be greatly appreciated!

    Reply
  14. It’s a pity you don’t have a donate button! I’d
    definitely donate to this outstanding blog! I guess for now i’ll
    settle for bookmarking and adding your RSS feed to my Google account.
    I look forward to new updates and will share this blog with my Facebook group.

    Chat soon!

    Reply
  15. This is very interesting, You’re a very skilled blogger.
    I’ve joined your rss feed and look forward to seeking more of your wonderful post.
    Also, I’ve shared your website in my social networks!

    Reply
  16. Pretty great post. I simply stumbled upon your blog and wanted to mention that I’ve really loved surfing around
    your weblog posts. After all I will be subscribing in your rss feed and I hope
    you write once more very soon!

    Reply
  17. Wow, superb blog layout! How long have you been blogging for?

    you make blogging look easy. The overall look of your web site is fantastic, let alone
    the content!

    Reply
  18. Hey there I am so glad I found your webpage, I really found you by mistake, while I was researching on Bing for something else, Regardless I am here now and would just like to say thanks for a tremendous post and a all round interesting blog (I also love the theme/design), I don’t have time to go through it all at the minute but I have saved it and also added your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the awesome work.

    Reply
  19. Hi there very nice site!! Man .. Beautiful ..
    Superb .. I will bookmark your website and take the feeds also?
    I am happy to find so many useful info right here within the submit, we need work out more
    strategies on this regard, thank you for sharing.
    . . . . .

    Reply
  20. I’m truly enjoying the design and layout of your website.
    It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more
    often. Did you hire out a developer to create your theme?
    Superb work!

    my web page :: coupon

    Reply
  21. Hiya very nice website!! Guy .. Excellent .. Superb
    .. I will bookmark your blog and take the feeds also?
    I am glad to seek out a lot of helpful information right here within the put
    up, we’d like develop extra strategies on this regard, thanks for sharing.
    . . . . .

    Reply
  22. A person necessarily help to make seriously posts I might state.
    That is the very first time I frequented your web page and so far?
    I surprised with the analysis you made to create
    this actual post extraordinary. Excellent activity!

    Reply

Leave a Comment