6

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?

Stephen
  • 803
  • 1
  • 11
  • 29

4 Answers4

4

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/

Stephen
  • 803
  • 1
  • 11
  • 29
  • @MisterJames That's hilarious! I had been using your suggested fix until I stumbled on your site looking for info on jquery migrate. In the post above I found this nugget. Watching your video on Building and Deploying Web Sites with ASP.NET MVC 4 at the minute :-) Many thanks for all that you do! – Stephen Feb 13 '13 at 08:49
3

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

Community
  • 1
  • 1
MisterJames
  • 3,306
  • 1
  • 30
  • 48
  • I have removed the .map file and everything is working again. I tried commenting out the reference as suggested in the above SO question, however this did not work. Many thanks. – Stephen Feb 01 '13 at 12:47
1

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.

Mohsen Sichani
  • 1,002
  • 12
  • 33
mcse3010
  • 174
  • 2
  • 10
0

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

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

it should have been

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

another giveaway that I should have noticed. I was getting the javascript error, but the file was a css file. Doh!

johnway2
  • 91
  • 4