Finding syntax errors in large javascript file in Visual Studio - javascript

Is there a way to tell Visual Studio to compile a particular javascript file and highlight any syntax errors, or to tell VS to include javascript syntax errors with line numbers the Errors listing? At the moment I have VS2010, but would like to know if this is possible in 2012 too.

Visual Studio doesn't compile Javascript. It is executed in your broswer. If anything crashes, your browsers console will tell you so in most of the cases. You could access the browsers console (dev-tools) with a keyboardshortcut (e.g. Chrome/Firefox CMD+ALT+i on MAC or CTRL+SHIFT+i on Windows).
In some cases (jquery with wrong selector) there is no error message; but if you really have syntax errors like missing brackets or something like that, you will find an error message at the console.
Perhaps you are looking for an extension like:
http://visualstudiogallery.msdn.microsoft.com/288a2b0f-1357-47b4-8215-1134c36bdf30

Related

UWP exclude "Microsoft C++ exception: Js::JavascriptException" exceptions for the WebView control

I have a UWP app with a WebView control. The app works fine however the Visual Studio 2017 output window shows a bunch of errors such as:
Exception thrown at 0x75ECB832 in MyApp.exe: Microsoft C++ exception: Js::JavascriptException at memory location 0x071FE1BC.
Exception thrown at 0x75ECB832 in MyApp.exe: Microsoft C++ exception: Js::JavascriptException at memory location 0x071FD83C.
etc...
The errors occur for instance on web pages such as http://www.google.com, even if I unmark all the exceptions from the "Exception Settings" window.
I could just ignore the exceptions, since they are probably minor javascript runtime errors, but they are also slowing down the debugger quite a bit.
Any advice on how to hide these exceptions from Visual Studio?
Check Debug tab in your project properties - what Debugger type you have there? If it's Native Only or Mixed, try to switch to Managed Only. Btw, if you switch to Script, Visual Studio will break at exact place where JS error is happening in the script.

How can I set up VS2015 to throw errors when I mess up my JavaScript?

When going through a code review, my technical lead picked up a few missing semicolons in my JavaScript when he went into debug. Visual Studio actually threw these exceptions up, and I was wondering where the option to turn that on was.
I've searched 'JavaScript Debugging in Visual Studio 20(15|13)', but it seems like there aren't any simple settings to enable.
Wondering the most efficient way to turn on JavaScript debugging in visual studio for all projects without having to add something each time.
Make sure you have Just My Code Enabled by going into Tools-->Options-->Debugger-->General--> Enable Just My Code. This will change your Debug--> Windows --> Exceptions Settings Dialog Box to show a CheckBox for JavaScript RunTime Exceptions.
Javascript RunTime Exceptions:
See this answer for previous versions of Visual Studio
Sounds like you want JSLint
You can also look into using TypeScript which is a superset of javascript and allows you to strongly type your javascript.

Visual Studio 2013 can't debug javascript in cshtml

I have an ASP.NET Web Application created with Visual Studio 2013. I am attempting to debug JavaScript in a CSHTML file. However, whenever I launch the webpage, any breakpoint turns into a red circle arrow and states, "The breakpoint will not currently be hit. No executable code of the debugger's target code type is associated with this line. Possible causes include: conditional compiliation, compilier optimizations, or the target architecture of this line is not supported by the current debugger code type."
Recently, the project was switched over to support MVC and RAZR, neither of which I know well, and this is exactly when this issue began. However, searching those have yielded results that don't fix my issue.
Web.config:
<compilation debug="true"...>
I know I can debug JavaScript with Firebug or some other browser tool, but I would much rather stick with Visual Studio's debug as that is what I am used to.
So, apparently this is a "known issue" that will be fixed as soon as possible. A temporary work around that works for "some" people is making sure any Javascript is in a separate file.
It is caused by having RAZR and Javascript in the same file and Visual Studio 2013 not being able to handle debugging in that instance.
I don't know what your particular problem is, but if you want to force a debug breakpoint to always happen, add debugger; to the line that you want it to stop on, and it will stop. This is regardless of where the JS is located (in a .js file, .html, cshtml, etc.)
Here is a blog post about it:
http://sumitmaitra.wordpress.com/2013/12/11/quickbytes-visual-studio-2013-and-javascript-debugging/
I also agree that JS should go in a .js file (which I've never had a problem adding a break point in a .js file), but for quick prototyping, this is a solution you can use.
If that still doesn't work, you can always you the F12 tools
The only browser that allows debugging a javascript file from Visual Studio is Internet Explorer. (this is what I found out after testing my application on different browsers)
I put my javascript in a separate file and debug with IE otherwise it will not work.
For some reason chrome doesnt allow you to step into the javascript.
One additional thing to check. If you have a App_Start|BundleConfig.cs (which came with MVC 4 - or maybe 3), set BundleTable.EnableOptimizations to false (or, like I did, wrap it in an #if !DEBUG #endif and take the default setting).
I tried and failed to use Chrome and then IE and ended up using the Firebug addon in Firefox, and I was able to debug and set breakpoints in my JS with no problems (in an MVC6 app on Visual Studio 2015 where this is apparently still an issue?!)...
FYI - When I tried to debug my JS in Chrome using the F12 Developer Tools, it told me it was not an option as the Debugger was already attached to another process...
For people coming here in 2017, I want to share that I had this same issue with VS2017 Enterprise RC, and with VS 2015 Community with any browser but Internet Explorer. Using IE did the trick for me.
Also, in VS2017, I had to add a debugger statement to get VS start looking at debug points.
Finally, I'd like to ask at least a comment from people voting down.

Command line tool for finding basic Javascript syntax errors?

Are there any command-line Linux tools that can catch basic syntax errors and compile time errors in my Javascript files, even if said Javascript files are written for use in a web browser?
I typically code my Javascript at the same time I'm coding my server side code in say Ruby or Perl. It would save me significant time if I could partially test my client side Javascript the same way I test my server side Ruby and Perl -- on the command line, typically from within emacs. I'm not expecting to catch run time JavaScript errors on the server, just basic things like a mistyped variable name or an extra bracket somewhere or a runaway string, things that could be found before actually attempting to execute the code.
What I do now to test/debug Javascript is the usual cycle of "visit web app in browser; check Firebug or other console; back to emacs to fix errors; repeat." Doing that is certainly unavoidable for more complex types of errors (e.g. involving user and network interaction) but a garden variety syntax error could be caught and dealt with more quickly on the command line without loading up the browser.
I've looked a bit into some server side platforms like node.js, but they all seemed geared toward writing and executing server side code (so all of the client side specific bits in my code would presumably make it barf). I also found an emacs mode for javascript REPL but it doesn't seemed designed to do just basic compile checks - it basically loads the whole page via an external graphical browser and lets you monkey with it, which is precisely what I'm trying to avoid.
Things like YUICompressor effectively do a syntax check too.
This isn't a direct answer to your question as it is a GUI tool, but I'm a big fan of Aptana. It uses SpiderMonkey to compile your code in the background and give you red squigglies for syntax errors as you type. (It also does the same for HTML.) It also tries to give you intellisense for JS, but it is hit-or-miss. It is nice when it works.
Since I probably haven't convinced you to change your development environment, let's answer your question directly. Why not use the SpiderMonkey engine to throw together a command-line app that does what you're looking for? It looks easy enough to plug in. You won't even have to worry about the fact that you're guaranteed to get runtime exceptions (there will be no DOM objects in your environment) — you don't have to actually execute the script. Just call JS_CompileScript and check for success. (And then destroy the JSScript object, of course.)
Or, if you're lazy, you could try Rhino Shell, which is a command-line Java tool which executes JavaScript.
I find JSHint, + its vim plugin are very useful. Light weight of vim and still be able to track the syntax errors of the javascript. JSHint can also be used as a command line tool.
https://github.com/walm/jshint.vim
Javascript debugger with a console in chrome:
The Chrome browser has a javascript debugger can find JavaScript errors:
In Chrome click Tools -> JavaScript Console:
This is examining a JavaScript page with the following code:
var error(){
}
And it tells me what is wrong with it, unexpected '('.
Telling me I can't define a function like that on line 14 of my javascript file.
If you click on the link next to the error, it will take you to and highlight the line that has the error/warning.
I wrote quick-lint-js for this purpose. It points out syntax errors, among other things.
quick-lint-js integrates with several code editors, such as Vim and Visual Studio Code. It also has a UNIX-style command-line utility if you prefer.

How to get readable syntax errors in Java Script?

Hi I am beginner in JS, Using linux ( Firefox, Chrome), Is there any way by which I get what are the syntax errors are there in my JS, the way I get my C syntax error in GCC?
Install Firebug, it will save your life!!!
Anyway in Firefox you can look into the error console in the tools menu and in Chrome you can open the javascript console in the tools menu.
if you use a script-editor like netbeans, it will show syntak errors on typing. for testing in a browser, i would suggest using firebug (and i'm sure theres something similar for chrome, too).
Chrome : ctrl + shift + j : this will bring up the JavaScript console. You can click the scripts tab to review page scripts.
FireFox : Install firebug and run it to get a similar console to the above stated chrome utilities.
IDE : You may wish to use netbeans or Eclipse which both offer syntax highlighting and code completion for JavaScript. These will indicate syntax errors at code time.
jslint/jshint : These tools offer code suggestions to improve your code quality and reduce the possibility of errors (logic) but will also break on syntax and other errors.

Categories