Robert Pouleijn
Robert Pouleijn

Reputation: 509

Failed to load template: (HTTP status: undefined undefined) after bundle minification in ASP.Net

I discovered that the javascript bundle with the AngularJs application didn't minify in release mode. It gave these kind of errors:

Minification failed. Returning unminified contents. (12834,21-27): run-time error JS1010: Expected identifier: delete

After resolving these errors the bundle did minify, however now the app won't startup anymore in the browser: it throws a

"Failed to load template error" on the first component.

So what can change in the minified javascript that breaks the loading of the angular template?

this is the bundle config:

      bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
    "~/scripts/jquery-{version}.js",
    "~/scripts/jquery.initialize.js",
    "~/scripts/jquery.scrollTo.min.js"));

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

  bundles.Add(new ScriptBundle("~/bundles/angular").Include(
    "~/scripts/underscore.js",
    "~/scripts/angular.js",
    "~/scripts/angular-animate.js",
    "~/scripts/i18n/angular-locale_nl-nl.js",
    "~/scripts/angular-ui/ui-bootstrap.js",
    "~/scripts/angular-ui/ui-bootstrap-tpls.js",
    "~/scripts/dir-pagination.js",
    "~/scripts/ng-ckeditor.js"));

  bundles.Add(new ScriptBundle("~/bundles/chart").Include(
    "~/scripts/moment.js",
    "~/scripts/chart.js",
    "~/scripts/angular-chart.js"));

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

  bundles.Add(new ScriptBundle("~/bundles/app").Include( //this bundle didn't minify but the app loaded properly, now that it does minify the templates won't load
      "~/scripts/AdminTemplate.js",
      "~/scripts/goalSeek.js",
      "~/scripts/app/app.js")
    .IncludeDirectory("~/Scripts/app/", "*.js", true));

  bundles.Add(new TemplateBundle("~/bundle/templates", _options)
    .IncludeDirectory("~/scripts/app/", "*.html", true));

This is the module declaration:

module Iop.Insight {  (() => {
"use strict";

var app = (<any>window).app = angular.module("InsightModule", ["ngAnimate", "ui.bootstrap", "chart.js", "ngLocale", "angularUtils.directives.dirPagination", "ngCkeditor"]);
app.config(config);
config.$inject = ["$compileProvider", "$uibTooltipProvider", "$httpProvider"];

function config($compileProvider, $uibTooltipProvider, $httpProvider) {
  $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?:|ms-excel:ofe\|u\||ms-word:ofe\|u\|)/);
  $compileProvider.debugInfoEnabled(true);
  $uibTooltipProvider.options({
    appendToBody: true
  });
  $httpProvider.defaults.transformResponse.push(responseData => {
    if (typeof responseData === "object") {
      //If the responseData is an object. We want to convert all Iso8601 DateTime strings within it to JavaScript Date object.
      new Iso8601ConversionService().convert(responseData);
    }

    return responseData;
  });
}

app.factory("_", ["$window", $window => $window._]);
app.filter("sanitize", ["$sce", $sce => htmlCode => $sce.trustAsHtml(htmlCode)]);   })(); }

The rest of the components and directives like:

module Iop.Insight {  class NavigatieController {  
static $inject = ["navigatieService"];  constructor(private navigatieService: NavigatieService){}

Upvotes: 4

Views: 687

Answers (1)

Robert Pouleijn
Robert Pouleijn

Reputation: 509

It turned out the template was loaded correct, but the corresponding angular component did a http request that "failed" because the minified version handles the resolve of the promise incorrectly if it contains an arrow function like so:

 IwillReturnUndefined(): Promise<string> {
  return this.test().then(
    (message) => {
      console.log('log something');
      return message;
    });
}

it will be minified like this:

  IwillReturnUndefined() {
      return this.test().then(n=>console.log("log something"), n)
  }

and thus returning the result of the console.log method. So I guess the angular error handling is faulty here and got me on the wrong track.

Upvotes: 1

Related Questions