【发布时间】:2016-04-21 06:53:13
【问题描述】:
我用 Yeoman 构建了一个应用程序,使用 generator-angular-jade-stylus,并且在使用 grunt serve 的开发版本中一切正常,在控制台中没有一个错误,但是在使用 grunt serve:dist 构建应用程序时,我的应用变成了一个空白页面,控制台出现以下错误:
66e3c8ac.vendor.js:4 Uncaught Error:
Failed to instantiate module monopolyApp due to:
Error: [$injector:nomod] Module 'monopolyApp' is not available! You
either misspelled the module name or forgot to load it. If registering
a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.15/$injector/nomod?p0=mon...
at http://localhost:9000/scripts/66e3c8ac.vendor.js:4:12729
at http://localhost:9000/scripts/66e3c8ac.vendor.js:4:20410
at b (http://localhost:9000/scripts/66e3c8ac.vendor.js:4:19993)
at http://localhost:9000/scripts/66e3c8ac.vendor.js:4:20305
at http://localhost:9000/scripts/66e3c8ac.vendor.js:4:27065
at Array.forEach (native)
at f (http://localhost:9000/scripts/66e3c8ac.vendor.js:4:13059)
at k (http://localhost:9000/scripts/66e3c8ac.vendor.js:4:27005)
at Fa (http://localhost:9000/scripts/66e3c8ac.vendor.js:4:28542)
at e (http://localhost:9000/scripts/66e3c8ac.vendor.js:4:18649)
我的尝试
我对此错误进行了大量研究,并找到了一些修复方法,但没有一个对我有用...其中一个提到 useminPrepare 会缩小脚本,然后 uglify 会再次缩小脚本,破坏了脚本,他们说要从 useminPrepare 块中删除 uglify 来解决它。我试过这个,它只是给了我一个错误,它找不到 uglify 任务,然后中止了。
我发现了另一个修复程序,将 <!-- build:js scripts/vendor.js --> 更改为 <!-- build:js(app/..) scripts/vendor.js --> 或 <!-- build:js(./) scripts/vendor.js --> -- 使用此方法从控制台中删除了错误,但仍然给我留下了空白页。
我已将模块正确附加到主体 body(ng-app="monopolyApp"),这就是我的模块在 app.js 中的定义方式:
angular
.module('monopolyApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute',
'LocalStorageModule'
])
在控制器中(main.js)
angular.module('monopolyApp')
.controller('MainCtrl', function ($scope, $window, $timeout, localStorageService) {
我还在this gist 中包含了 index.jade、app.js 和 main.js 以供进一步参考。如果需要任何进一步的信息来诊断此错误,请告诉我,但我已经尝试了所有可以找到的修复程序,但没有任何效果。任何帮助表示赞赏。谢谢!
【问题讨论】:
标签: javascript angularjs gruntjs yeoman yeoman-generator-angular