AngularJS未捕获错误:$ injector:modulerr

问题描述:

我知道有一百万个这样的问题,而且我一直在用AngularJS编码一段时间,但这个是不寻常的。

2周前我为客户部署了一个网站,一切都运行的很好。然后客户决定他想要一个小小的改变,所以在进行更改之前,我在本地服务器上运行了该网站,以确保一切正常。

然后这个错误弹出...我不知道它是什么意思,我没有做任何改变的代码。它与完美运行的已部署网站相同。有人会知道这个错误意味着什么吗?

Failed to instantiate module crsportal due to: 
Error: [$injector:modulerr] http://errors.angularjs.org/1.5.7/$injector/modulerr?p0=c...) 
    at Error (native) 
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:6:412 
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:40:134 
    at r (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:7:355) 
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:39:222) 
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:39:391 
    at r (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:7:355) 
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:39:222) 
    at db (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:43:246) 
    at c (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:20:359 

我可以给你的代码,因为也许我改变了一些东西而没有意识到它。

crsportal.js

(function() { 
    'use strict'; 

    angular 
    .module('crsportal', [ 
     'crs.authentication', 
     'crs.config', 
     'crs.routes', 
     'crs.profiles.controllers', 
     'profile.services', 
     'route.controller' 
    ]); 

    angular 
    .module('crs.config', []); 

    angular 
    .module('crs.profiles.controllers', []); 

    angular 
    .module('crs.routes', ['ngRoute']); 

    angular 
    .module('profile.services', []); 

    angular 
    .module('route.controller', []); 

    angular 
    .module('crsportal') 
    .run(run); 

    run.$inject = ['$http']; 

    /** 
    * @name run 
    * @desc Update xsrf $http headers to align with Django's defaults 
    */ 
    function run($http) { 
     $http.defaults.xsrfHeaderName = 'X-CSRFToken'; 
     $http.defaults.xsrfCookieName = 'csrftoken'; 
    } 

})(); 

的index.html

<!DOCTYPE html> 
<html> 
<head> 
    <title>CRS Client Portal</title> 

    <base href="/" /> 

    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

    <!-- The HTML5 Shim is required for older browsers, mainly older versions IE --> 
    <!--[if lt IE 9]> 
     <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> 
    <![endif]--> 
    <!--[if lt IE 7]> 
    <div style=' clear: both; text-align:center; position: relative;'> 
     <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode"><img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" alt="" /></a> 
    </div> 
    <![endif]--> 

    <script> 
     (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
     (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
     m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
     })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); 

     ga('create', 'UA-84093208-1', 'auto'); 
     ga('send', 'pageview'); 
    </script> 
    {% include 'stylesheets.html' %} 
    <!-- Latest compiled and minified CSS --> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
</head> 

<body ng-app="crsportal" class="loginpage"> 
    <div class="container-fluid" ng-controller="LoginController as vm"> 
     {% include 'login.html' %} 
    </div> 

    {% include 'javascripts.html' %} 
</body> 
</html> 

编辑:新增信息

authentication.module.js

(function() { 
    'use strict'; 
    angular 
    .module('crs.authentication', [ 
     'authentication.controllers', 
     'authentication.services' 
    ]); 

    angular 
    .module('authentication.controllers', []); 

    angular 
    .module('authentication.services', ['ngCookies']); 
})(); 

javascripts.html

<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script> 
<script type="text/javascript" src="{% static 'bower_components/bootstrap-material-design/dist/js/material.js' %}"></script> 
<script type="text/javascript" src="{% static 'bower_components/bootstrap-material-design/dist/js/ripples.js' %}"></script> 
<script type="text/javascript" src="{% static 'bower_components/underscore/underscore.js' %}"></script> 

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-route.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-cookies.js"></script> 


<script type="text/javascript" src="{% static 'bower_components/ngDialog/js/ngDialog.js' %}"></script> 
<script type="text/javascript" src="{% static 'lib/snackbarjs/snackbar.min.js' %}"></script> 

<script type="text/javascript" src="{% static 'javascripts/crsportal.js' %}"></script> 

<script type="text/javascript" src="{% static 'javascripts/config.js' %}"></script> 
<script type="text/javascript" src="{% static 'javascripts/routes.js' %}"></script> 
<script type="text/javascript" src="{% static 'javascripts/authentication/authentication.module.js' %}"></script> 
<script type="text/javascript" src="{% static 'javascripts/authentication/services/authentication.services.js' %}"></script> 
<script type="text/javascript" src="{% static 'javascripts/authentication/controllers/login.controller.js' %}"></script> 
<script type="text/javascript" src="{% static 'javascripts/authentication/controllers/logout.controller.js' %}"></script> 
+1

错误:[$注射器:modulerr] http://errors.angularjs.org/1.5.7/$injector/modulerr?p0=c。 ..)这是什么完整的网址? – NicolasMoise

+0

无法找到角模块之一。你必须弄清楚哪一个。 – NicolasMoise

+0

http://errors.angularjs.org/1.5.7/$injector/modulerr?p0=crs.authentication&p1=Error%3A%20%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs。有机%2F1.5.7%2F%24injector%2Fnomod%3Fp0%3Dcrs.authentication%0A%20%20%20%20原子%20Error%20(天然)%0A%20%20%20%20原子%20https%3A%2F %2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.7%2Fangular.min.js%3A6%3A412%0A%20%20%20%20at%.....(太长以至于无法包含整个链接) –

你缺少了 “crs.authentication” 模块还没有被实例化的时候,你运行

angular 
    .module('crsportal', [ 
     'crs.authentication', 
     'crs.config', 
     'crs.routes', 
     'crs.profiles.controllers', 
     'profile.services', 
     'route.controller' 
    ]); 

AngularJS: Uncaught Error: [$injector:modulerr] Failed to instantiate module?

+1

对不起,我不确定你的意思是什么?该链接描述了某人在其脚本之后加载angular.js的问题。这不是同一个问题,除非我错过了一些东西。 –

+0

Angular可能无序加载模块。 – Phil

+0

@菲尔权利,但你真的认为在这种情况下是这样吗? –

确保存在的定义:

//i added this 
angular.module('crs.authentication', []); 

angular 
.module('crs.config', []); 

angular 
    .module('crs.profiles.controllers', []); 
//make sure no other module references ngRoute or this could be a problem as well. if it does add it as a depenency 
angular 
    .module('crs.routes', ['ngRoute']); 

angular 
    .module('profile.services', []); 

angular 
    .module('route.controller', []); 
//i moved this to last 
angular 
    .module('crsportal', [ 
    'crs.authentication', 
    'crs.config', 
    'crs.routes', 
    'crs.profiles.controllers', 
    'profile.services', 
    'route.controller' 
]); 

小提琴,显示这个工程:http://jsfiddle.net/ncapito/ku3c33bj/

+0

这是完全不正确 – Phil

+0

请详细说明,以便我可以修复。 – Nix

+0

模块不需要按任何特定顺序定义。在模块配置和运行之前,Angular会依赖关系树运行 – Phil