【问题标题】:Unable to instantiate module on production无法在生产中实例化模块
【发布时间】:2014-07-14 02:26:18
【问题描述】:

我刚刚将我的程序推送到 heroku 上,我测试 angular 的页面加载了以下错误:

未捕获的错误:[$injector:modulerr] 无法实例化模块 diceAngularApp,原因如下: 错误:[$injector:unpr] 未知提供者:t

它在开发中工作得非常好,所以我不确定问题可能是什么。要查看错误,您可以访问 www.firexion.com/dice 上的页面

我不确定问题的确切位置,因此我不确定要共享哪个代码。这是它的 github 链接:https://github.com/Firexion/hundred

我猜它可能在 angular app.js 中?:

'use strict';

angular
.module('diceAngularApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute'
])
.config(function ($routeProvider) {
$routeProvider
  .when('/dice', {
    templateUrl: '../../views/dice/main.html',
    controller: 'DiceController'
  })
  .otherwise({
    redirectTo: '/dice'
  });
});

或者我在我的 Rails 应用程序 javascript 文件 lumen.js 中包含错误:

// Lumen
// Bootswatch
//= require jquery-2.1.0
//= require jquery_ujs
//= require lumen/loader
//= require lumen/bootswatch

// angular
//= require angular/angular
//= require angular/angular-cookies
//= require angular/angular-resource
//= require angular/angular-route
//= require angular/angular-sanitize
//= require angular/angular-scenario

// dice
//= require dice/app.js
//= require dice/controllers/main.js
//= require dice/dice.js

感谢您提供的任何帮助。

【问题讨论】:

    标签: javascript ruby-on-rails angularjs heroku


    【解决方案1】:

    我强烈怀疑,基于 Angular 正在寻找变量 t 的提供者这一事实,我猜你不会命名服务/控制器/等。 t 是您在某处使用压缩/编译器,这会破坏您的变量。

    要解决这个问题并确保编译器的安全,您需要调整语法。完整的细节here,但下面是瘦的。

    myapp.config(['$routeProvider', function($routeProvider) {
      $routeProvider.when('hello/:queryId', {
        templateUrl: 'mypartial.html',
        controller: MyCtrl,
        controllerAs: 'myCtrl',
        resolve: {
          'myParam': ['myService', '$route', function(myService, $route) {
            return myService.get($route.current.params.queryId);
          }]
        }
      });
    

    【讨论】:

    • 好的,我一直在尝试遵循这一点,并且我“认为”我的 app.js 已经正确设置以防止这种情况发生?你是对的,我没有命名任何东西。看起来它试图将 $routeProvider 称为 t 并且据我所知,我没有错误地传递它。很混乱。我认为我没有设置任何东西来缩小这个,也许这是 heroku 为你做的事情?
    • 哦,看起来 Rails 有一个默认设置,使用 uglifier 进行生产压缩,而不是开发。似乎这可能是缩小的罪魁祸首,但我仍然不确定我的 app.js 和 main.js 有什么问题导致提供者无法通过缩小器,因为我认为它没有被变量引用任何地方
    • 好吧,我只想写这篇文章,直到糟糕的一天。我尝试关闭uglifier并将其推到heroku,没有。把它拉回来,发现我忘记了我的一个控制器功能中的乘法。想我不妨把这个改变推到heroku,因为为什么不呢,突然页面就完美了???我不明白,但它正在工作,我非常感谢您对缩小的建议
    • 我将控制器和配置更改为这种表示法,并且错误已解决。谢谢!!
    • 我还是不明白?那么这里到底有什么问题呢?我正在尝试将我的应用程序推向生产,但我使用 coffescript 的事实使理解这个答案变得更加困难。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    • 2014-06-04
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多