Uncaught ReferenceError: jQuery is not defined in laravel

How to fix it ? after this error i am doing some changes in html template it wouldn’t change,delete or comment… and it also creating problem in my backend

The error is obvious — you are referencing a variable that hasn’t been defined (jQuery in this case). E.g.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>jQuery</title>
  </head>
  <body>
    <script>jQuery('body').css('background', 'red');</script>
  </body>
</html>

Output:

ReferenceError: jQuery is not defined

The simple answer would be to include the jQuery library.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>jQuery</title>
  </head>
  <body>
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script>jQuery('body').css('background', 'red');</script>
  </body>
</html>

Assuming things worked, then you altered the template, then they didn’t, I’d guess you deleted the code to include the library, or made some other change that means laravel can’t find it.

However, according to this SO answer, jQuery should already included in laravel as a dev dependency and you should be able to include it using:

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

More ideas here:

HTH

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.