$ injector:modulerr模块在IIS上发布应用程序后出错

时间:2015-12-09 12:43:31

标签: javascript angularjs iis obfuscation minifiedjs

我在IIS服务器上发布AngularJS应用程序后出现问题 我认为这与javascript混淆和缩小有关,但我不知道如何修复它......

这就是我的app.js的样子

angular.module('app', ['LocalStorageModule', 'angular-loading-bar', 'smart-table', 'mgcrea.ngStrap', 'ngAnimate', 'ngSanitize', 'ngRoute', 'ui.router', 'LocalStorageModule', 'app.filters', 'app.services', 'app.directives', 'app.controllers'])

.config(['$stateProvider', '$locationProvider', function ($stateProvider, $locationProvider) {

    $stateProvider
        .state('home', {
            url: '/',
            layout: 'basic',
            templateUrl: 'views/index',
            controller: 'HomeCtrl'

        })
        .state('putninalozi', {
            url: '/putninalozi',
            layout: 'basic',
            templateUrl: 'views/PutniNalozi',
            controller: 'PutniNaloziCtrl'
        })
        .state('profil', {
            url: '/profil',
            layout: 'basic',
            templateUrl: 'views/profil',
            controller: 'ProfilCtrl'
        })
        .state('login', {
            url: '/login',
            layout: 'basic',
            templateUrl: 'views/login',
            controller: 'LoginCtrl'
        })
        .state('signup', {
            url: '/signup',
            layout: 'basic',
            templateUrl: 'views/signup',
            controller: 'SignUpCtrl'
        })
        .state('otherwise', {
            url: '*path',
            templateUrl: 'views/404',
            controller: 'Error404Ctrl'
        });

    $locationProvider.html5Mode(true);

}])

.config(function ($httpProvider) {
    $httpProvider.interceptors.push('authInterceptorService');
})

.run(['authService', '$templateCache', '$rootScope', '$state', '$stateParams', function (authService, $templateCache, $rootScope, $state, $stateParams) {

    authService.fillAuthData();
    $rootScope.$state = $state;
    $rootScope.$stateParams = $stateParams;

}]);

例如我的一个控制器看起来像这样

.controller('LoginCtrl', ['$scope', '$location', '$timeout', '$window', 'authService', function ($scope, $location, $timeout, $window, authService) {

     $scope.loginData = {
         userName: "",
         password: ""
     };

     $scope.message = "";

     $scope.login = function () {

         authService.login($scope.loginData).then(function (response) {

             $location.path('/putninalozi');

         },
          function (err) {
              $scope.message = err.error_description;
          });
     };

 }])

知道如何解决这个问题吗?感谢您的所有意见

我的BundleCOnfig.cs看起来像这样

public class BundleConfig
{
    // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new StyleBundle("~/content/css/app").Include("~/content/app.css")
                                                        .Include("~/content/custom.css")
                                                        .Include("~/content/loading-bar.css"));


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

        bundles.Add(new ScriptBundle("~/js/app").Include(
              "~/scripts/vendor/angular.min.js",
              "~/scripts/vendor/smart-table.js",
              "~/scripts/vendor/angular-strap.min.js",
              "~/scripts/vendor/angular-strap.tpl.min.js",                    
              "~/scripts/app.js",
              "~/scripts/vendor/jquery-2.0.3.min.js",
              "~/scripts/vendor/angular-ui-router.js",
              "~/scripts/vendor/loading-bar.js",
              "~/scripts/vendor/angular-animate.js",
              "~/scripts/vendor/angular-route.js",
              "~/scripts/vendor/angular-sanitize.min.js",
              "~/scripts/vendor/angular-local-storage.min.js",
              "~/scripts/vendor/bootstrap.js",
              "~/scripts/controllers.js",
              "~/scripts/filters.js",
              "~/scripts/services.js",
              "~/scripts/directives.js"));
    }
}

3 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,但我认为我找到了解决方案。它看起来像在本地服务器上(来自Visual Studio)默认选项BundleTable.EnableOptimizations为false。但是当您在服务器上发布IIS时,这是真的。尝试在 BundleConfig.cs

中添加 BundleTable.EnableOptimizations = false

答案 1 :(得分:0)

要启用缩小功能,请确保以下内容:

  • Config.asax,注册BundlesConfig

    protected void Application_Start()
    {
        BundlesConfig.RegisterBundles(BundleTable.Bundles);
    }
  • BundleConfig.cs,包含脚本并启用优化

    public static void RegisterBundles(BundleCollection bundles)
    {
      bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
        "~/Scripts/jquery-{version}.js"));
    
      BundleTable.EnableOptimizations = true;
    }
  • main.html,注册脚本

    @section scripts {
      @Scripts.Render("~/bundles/jquery")
    }
    
  • 此外,缩小过程会将$ scope和$ q更改为随机变量。由于这不会告诉angular注入什么,解决方案是声明包含在[]中的依赖项:

    angular.module("MyApp")
      .controller("MyCtrl", ["$scope", "$q", function($scope, $q) {
      // your code
    }])
    

这只是启用缩小所需的步骤。 This是关于如何实现此

的文章

答案 2 :(得分:0)

你在ScriptBundle中删除了angular.min,angular-local-storage.min并添加了它们的未分类版本