Request explanation - Uncaught ReferenceError message

Richard Rosenheim 66 Reputation points

I have an ASP.NET MVC (using .NET 4.8 Framework) application. In Visual Studio 2022, when I run the app in debug mode, I get the error message:

Uncaught ReferenceError ReferenceError: $ is not defined
    at <anonymous (localhost:24995/(index):22:36:27:9

I'm assuming that the numbers are (hopefully) line numbers. But in what file?
Presumably the $ refers to jQuery statements, but those numbers don't relate to any lines in the view with jQuery statements. For example, line 22 in the Index view would be the "End Code" statement. Can someone help shine a light on understanding what those numbers mean? Interestingly, all my jQuery appears to work just fine.

A set of technologies in the .NET Framework for building web applications and XML web services.
3,303 questions
{count} votes

Accepted answer
  1. Bruce ( 57,641 Reputation points

    javascript stack trace reports:

    <functionname> <filename> line number:column.

    the format can very by javascript engine. in your case it an anonymous function in the index page html at line 22, column 36. not sure why the second line 29 column 9.

    you would need to view source in the browser of the index page to see the line number.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Bruce ( 57,641 Reputation points

    most likely you are running inline jQuery code before jQuery is defined. if you view page source in the browser, you will probably see javascript using jQuery before the jQuery include at the bottom of the file.

    the fix is to be sure script in view is defined in the scripts section.

    0 comments No comments

  2. Richard Rosenheim 66 Reputation points

    Thank everyone for responding. The thrust of my question wasn't that there was an issue with jQuery. I knew that by the fact of the dollar sign. My question was how to interpret the error message. Specificity, the "22:36:27:9" portion. I'm thinking those are line numbers being referenced, but none of the lines corresponding to those numbers contains any jQuery code. My goal for posting this question is to hopefully understand how to read the error message so that when I have another issue in the future, I can actually locate the line in question. Next time, the issue may not be so obvious as a dollar sign and it would be nice to actually know which line is causing the problem. (For anyone wishing to know, the actual issue was mismatched version numbers between the version of JQuery being packaged, and what the <script> tag specified.)

    0 comments No comments