Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net mvc Updated jquery now getting critical error

I updated jquery today through NuGet and I am now receiving the following error:

JavaScript critical error at line 1, column 11 http://localhost:53779/Scripts/jquery-1.9.0.min.map

SCRIPT1004: Expected ';'

Has anyone else come across this and can suggest a solution?

like image 372
Stephen Avatar asked Jan 24 '13 17:01

Stephen


3 Answers

I stumbled on this by accident today and thought I should respond with an actual fix to this problem.

In my BundleConfig.cs I had the following:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
            "~/Scripts/jquery-1.*"));

The wildcard was being used to get the latest version of jQuery, however, the Bundle Builder was picking up the map file as well.

By updating the BundleConfig.cs as follows:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
            "~/Scripts/jquery-{version}.js"));

This solved the problem. The {version} token is a replacement that does a best match against the file. So now instead of all the files getting added you get a match on the library you are requesting for bundling and minification.

Source for this fix was found here http://jameschambers.com/2013/01/jquery-script-map-causing-critical-error-in-jquery-1-9-0/

like image 199
Stephen Avatar answered Sep 20 '22 19:09

Stephen


The .map file is used for debugging (for example, there are new features in Chrome that let you 'map' into the non-minified version of the source).

If you're using bundling/minification you can link to the full version of the file, so you can delete (or move) the .map file safely and the code will work again, and you'll still get minification through the MVC framework.

As a note, I'm assuming you're not doing any jQuery library work here, and that you're not currently needing to access the non-minified version while debugging in the browser. More often than not, I'm a "consumer" of jQuery and tend not to look into the black box.

For more info, Elijah has some great info on the point of the source map and how you can use it.

http://www.elijahmanor.com/2013/01/the-magic-of-jquery-source-map.html

As well, if you want to implement a temporary workaround to address the map minification problem (may be related) you can check out this SO question: jquery 1.9.0 and modernizr cannot be minified with the ASP.NET Web Optimization Framework

like image 32
MisterJames Avatar answered Sep 21 '22 19:09

MisterJames


Another possible cause of this issue is if you define two bundles with the same name (one script, one style):

    bundles.Add(new ScriptBundle("~/bundles/bootstrap")
            .Include("~/Scripts/bootstrap.js"));

    bundles.Add(new StyleBundle("~/bundles/bootstrap")                        
            .Include("~/Content/bootstrap.css"));

Then, in page, doing the following:

     <%=Scripts.Render("~/bundles/bootstrap")%>

It will attempt to render the css as javascript and will fail.

like image 22
mcse3010 Avatar answered Sep 21 '22 19:09

mcse3010