Reputation: 39
I'm getting Unable to cast object of type 'Microsoft.Ajax.Utilities.CallNode' to type 'Microsoft.Ajax.Utilities.AstNodeList. on
@Scripts.Render("~/bundles/bootstrap")
This has to be something really stupid but I couldn't find it anywhere. Any ideas?
Upvotes: 0
Views: 1131
Reputation: 501
I had the same error, fairly misleading.
In my case the issue was using JS template literals:
//this was breaking the minification
$(`#someId form input[data-sku=${this.getSku()}]`).val()
//this fixed it
$("#someId form input[data-sku=" + this.getSku() + "]").val()
//other examples that might break the minification:
//null propagation
hide = hide ?? true; //<-- this breaks
hide = hide ? hide : true; //<-- this fixes
//rgba syntax
someButton.css("color","rgb(255 0 0/ 50%)"); //<-- this breaks
someButton.css("color","rgba(255, 0, 0, 127)"); //<-- this fixes
//implicit object declaration
//this breaks
var data = {
originalItemKey,
alternativeSku
};
//this fixes
var data = {
originalItemKey: originalItemKey,
alternativeSku: alternativeSku
};
//usage of "let" and "const" keyword might break at times, but not always.
//In my case, it did happen that "some" usages of const and let did break the minification, therefore:
//IF this might break
let someVariable = "some value";
//this fixes
var someVariable = "some value";
//IF this might break
const someConst = "some const value";
//this fixes
var someConst = "some const value";
Apparently it's a known issue in Microsoft.Web.Optimization:
Microsoft.AspNet.Web.Optimization JavaScript bundling fails to minify template literals
Upvotes: 1
Reputation: 153
Check the scripts in the bundle. There must be a error in the script. Most probably the below error must be present
Instead of
$("#myElement")
you might have typed
$("#
myElement")
Thanks, R. Venkatesan
Upvotes: 2