'I Can Only Add Breakpoints to Certain JavaScript Files in Visual Studio?

I'm having an issue where I have multiple JavaScript files, but only some of them allow me to add breakpoints within Visual Studio 2022. Files where I can't give the message "Breakpoint will not be hit. Breakpoint set but not yet bound".

I believe the issue to be that only Javascript files with methods that are called by events in the Cshtml allow breakpoints, but JS files with method only called by JavaScript don't allow for breakpoints.

Any guidance or help to understand this would be greatly appreciated. I've attached a couple of pictures.

Breakpoint able to be set, file A.

Breakpoint not able to be set, file B.



Solution 1:[1]

According to the following link, you can see that “For ASP.NET and ASP.NET Core, debugging embedded scripts in CSHTML files is not supported. JavaScript code must be in separate files to enable debugging.”.

Link: https://docs.microsoft.com/en-us/visualstudio/javascript/debug-nodejs?view=vs-2022

You can follow the steps in the link above to debug a JavaScript in Visual Stuido.

You might also use Chrome Developer Tools or F12 Tools for Microsoft Edge instead. See this.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jingmiao Xu-MSFT