Uncaught Error: $injector:modulerr; works locally but not on server

Uncaught Error: $injector:modulerr; works locally but not on server

以下代码在我的本地开发环境中运行良好,但是当我将解决方案托管在服务器上时出现以下错误,在使用未压缩的 js 后出现以下错误:

angular.js:66 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
    ReferenceError: shallowCopy is not defined

下面是相关代码,我的 index.php 文件包括所有文件和正在注入我的指令的 app.js 文件:

index.php:

<!-- bootstrap/jquery -->
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">

<script src="js/jquery/jquery-3.1.1.min.js"></script>
<script src="js/jquery/jquery-ui.min.js"></script>
<link rel="stylesheet" href="styles/jquery/jquery-ui.min.css" />

<link rel="stylesheet" href="styles/bootstrap-3.3.7-dist/css/bootstrap.css" />
<script src="styles/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script src="plugins/Bootstrap-3-Typeahead-master/bootstrap3-typeahead.min.js"></script>
<!-- end bootstrap/jquery -->
<!-- custom css -->
<link rel="stylesheet" href="styles/styles.css" />
<!-- end custom css -->
<!-- favicon -->
<link rel='shortcut icon' type='image/x-icon' href='media/images/favicon.ico' />
<!-- end favicon -->

<!-- custom js -->
<script src="js/main.js"></script>
<!-- end custom js -->

<!-- angularjs -->
<script src="js/angularjs/angular.min.js"></script>
<script src="js/angularjs/angular-route.min.js"></script>
<script src="js/angularjs/angular-sanitize.js"></script>

<script src="js/app.js"></script>
<script src="js/login/login.js"></script>
<script src="js/questionnaire/questionnaire.js"></script>
<script src="js/study/study.js"></script>
<script src="js/result/result.js"></script>
<!-- end angularjs -->
<div class="row" ng-app="app" >
    <div ng-view>
    </div>
</div>

app.js:

// app.js
(function () {

  "use strict";

  // Creating the Module
  angular.module("app", ["ngRoute", "ngSanitize"])
    .config(function ($routeProvider) {
        //$location.path('/questionnaire'); //logged in already, session still active

      $routeProvider.when("/", {
        controller: "loginController",
        controllerAs: "vm",
        templateUrl: "views/login.php"
      });

      $routeProvider.when("/questionnaire/", {
        controller: "questionnaireController",
        controllerAs: "vm",
        templateUrl: "views/questionnaire.php"
      });

      $routeProvider.when("/questionnaire/:survey", {
        controller: "questionnaireController",
        controllerAs: "vm",
        templateUrl: "views/questionnaire.php"
      });

      $routeProvider.when("/study/:studyid", {
        controller: "studyController",
        controllerAs: "vm",
        templateUrl: "views/study.php"
      });

      $routeProvider.when("/result/", {
        controller: "resultController",
        controllerAs: "vm",
        templateUrl: "views/result.php"
      });

      $routeProvider.otherwise({ redirectTo: "/" });

    });

})();

可能是js压缩的问题,ref https://docs.angularjs.org/guide/di#implicit-annotation

尝试以下操作,注意 ['$routeProvider...:[=​​12=]

用这个替换你的代码

(function () {

  "use strict";

angular.module("app", ["ngRoute", "ngSanitize"])
    .config(['$routeProvider', function ($routeProvider) {
        //$location.path('/questionnaire'); //logged in already, session still active

  $routeProvider.when("/", {
    controller: "loginController",
    controllerAs: "vm",
    templateUrl: "views/login.php"
  });

  $routeProvider.when("/questionnaire/", {
    controller: "questionnaireController",
    controllerAs: "vm",
    templateUrl: "views/questionnaire.php"
  });

  $routeProvider.when("/questionnaire/:survey", {
    controller: "questionnaireController",
    controllerAs: "vm",
    templateUrl: "views/questionnaire.php"
  });

  $routeProvider.when("/study/:studyid", {
    controller: "studyController",
    controllerAs: "vm",
    templateUrl: "views/study.php"
  });

  $routeProvider.when("/result/", {
    controller: "resultController",
    controllerAs: "vm",
    templateUrl: "views/result.php"
  });

  $routeProvider.otherwise({ redirectTo: "/" });

}]);

})();

我遇到了同样的问题。

我通过将我最近添加的插件 include 移动到我的底部来解决它 bundles.Add(我的 appstart 中的新 ScriptBundle

此更改对我有用,它在本地运行良好但在实时环境中崩溃。