1

My package.json file has devDependency for jquery as

"jquery": "^3.3.1",

I ran an npm install, build and then npm run dev after that.

My default blade template file has the scripts loading in the bottom as

<script src="{{ mix('/js/app.js') }}"></script>

@yield('js')

and I am using javascript in my view as

@section('js')
    <script type="text/javascript">
        $(document).ready(function(){
            $('#centerhead').click(function(){
                alert('test js');
            });
        });
    </script>
@stop

yet I am getting Uncaught ReferenceError: $ is not definederror on the console when I am trying to use jQuery. Javascript works fine though.

1
  • possible dupe: stackoverflow.com/questions/46939027/… ... check where in the node_modules you're loading jquery from and if you're binding $ to the window Commented Mar 5, 2019 at 2:37

2 Answers 2

1

Solved. After runing the npm install jquery was installed in the node modules folder. I had to write window.$ = window.jQuery = require('jquery') in my bootstrap.js file. After that I ran an npm run dev and things started working.

Sign up to request clarification or add additional context in comments.

Comments

0

Try below in your blade file.

<script src="{{asset('js/jquery-3.1.1.min.js')}}"></script>
<script src="{{asset('js/app.js')}}"></script>

which frontend framework you are using?

1 Comment

I am using blade which came with the laravel. I actually do not have jquery in my resources folder. Even after doing an npm install I only get that inside the node modules folder only.

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.