2

I'm trying to get jQuery to work with Laravel 5.4. I installed jQuery with npm. I have two files in the same folder: app.js and bootstrap.js. From app.js I import the file bootstrap.js with:

require('./bootstrap');

In bootstrap.js I import jQuery with:

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

Still in my blade view when I try:

<script>
    $(document).ready(function () {
        console.log('jQuery is working!');
    });
</script>

I get a reference error telling me that "$ is not defined".

Any idea of what I am doing wrong? Thank you in advance.

1 Answer 1

1

Did you include it in your view? You need to put in something like this:

<script src="{{ mix('js/app.js') }}"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes! But I had the async attribute set to async in my script tag. Solved it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.