Request explanation - Uncaught ReferenceError message

Richard Rosenheim 66 Reputation points
2023-04-13T00:44:08.78+00:00

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.

ASP.NET
ASP.NET
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 (SqlWork.com) 57,641 Reputation points
    2023-04-16T19:37:59.51+00:00

    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 (SqlWork.com) 57,641 Reputation points
    2023-04-13T15:41:57.4933333+00:00

    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
    2023-04-16T03:29:52.94+00:00

    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