.net mvc Updated jquery now gets critical error

I updated jquery today via NuGet and now I get the following error:

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

Anyone else come across this and can offer a solution?

+6
source share
4 answers

I accidentally stumbled upon this today and thought that I should respond with the actual fix for this problem.

In my BundleConfig.cs, I had the following:

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

The wildcard was used to get the latest version of jQuery, however Bundle Builder also compiled a map file.

By updating BundleConfig.cs as follows:

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

This solved the problem. The {version} token is the replacement that best matches the file. So, now instead of all the files you add, you get a match for the library that you request for linking and minimization.

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

+4
source

The .map file is used for debugging (for example, in Chrome there are new features that allow you to "display" in a non-minified version of the source).

If you are using layout / mini-code, you can reference the full version of the file so that you can safely delete (or move) the .map file and the code will work again and you will still get the MVC structure.

As a note, I assume that you are not running any jQuery library here, and that you currently do not need access to an invalid version when debugging in the browser. Most often, I am a β€œconsumer” of jQuery and, as a rule, do not look in the black box.

For more information, Elijah has excellent information about the point on the source map and how you can use it.

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

Also, if you want to apply a temporary workaround to solve the map minimization problem (may be related), you can check this SO question: jquery 1.9.0 and modernizr cannot be minimized using ASP.NET web optimization

+3
source

Another possible cause of this problem is the definition of two packs 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 on the page do the following:

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

It will try to display css as javascript and fail.

+1
source

I messed up because I cut and pasted the wrong thing. I had

 @Scripts.Render("~/Content/DataTables/css") 

he should have been

 @Styles.Render("~/Content/DataTables/css") 

one more hand I should have noticed. I was getting a javascript error, but the file was a css file. Doh!

0
source

All Articles