I have a website running on MVC4 using the following javascript libraries.
jQuery, jQueryValidate, Bootstrap, FineUploader, MaskedInput, Knockout and Modernizr. I also have my app specific javascript in there as well. They are all loaded using the Script Bundling feature from the System.Web.Optimization
namespace. My bundle looks like this.
bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
"~/Scripts/jquery-1.7*",
"~/Scripts/modernizr.*",
"~/Scripts/bootstrap*",
"~/Scripts/jquery.validate.*",
"~/Scripts/jquery.maskedinput-1.3.*",
"~/Scripts/MyApp*",
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/knockout-*",
"~/Scripts/jquery.fineuploader-3.0.js"));
But for some reason while the site works normally on my dev system and when testing, it fails in production with javascript errors. There error makes no sense to me...
Uncaught ReferenceError: options is not defined
Now when I check the javascript file everything is of course minified and compressed so no luck deciphering anything from that. Has anyone else encountered odd behavior like this from Bundling?
So after fighting with this thing frantically (since I had publishing a broken build) I switched my dev copy to always apply optimizations even if it was ina Debug build.
BundleTable.EnableOptimizations = true;
And I was getting the same issue on my machine now (at least it's consistant). I started think ing about what changed in this version and the only things that were modified since the previous publish were some updates from Nuget packages and some code changes to administrative tasks. I started to track down the Nuget package changes and checked into the ones that had javascript changes with them, hoping to find a clue. After going though each one I went to test out the page and the issue was gone, but I hadn't made any changes yet! However I did come across one that gave me a prompt when I tried to view it.
I had absently mindedly clicked [Yes] when I saw this, but when the issue went away I reverted the change and tried the site again and the JavaScript error was back again. I had pasted in some changes to this file to set the context of this
to the element triggering the ajax request. I had done this before but I needed to reapply the change after updating the source package from Nuget. At the time I think I had done this in Sublime and I guess it copied in some Linux style line endings.
So long story short, there appears to be a bug in the System.Web.Optimization namespace's Bundling feature that chokes on Linux style line endings. I hope this helps anyone else who might suffer from this problem.