1

当我的应用程序使用 dokku 部署到我们的登台服务器时出现错误Error: [$injector:unpr] Unknown provider: IdleProvider,但在本地计算机上运行它时我没有得到它。我在用着ng-idle 1.2.1

我发现这个问题被问了很多次,但原因总是与更改1.0.0服务名称的版本中所做的更改有关。我唯一能想到的是代码的缩小是问题,但据我所知,代码应该没问题,但我不是专家。任何帮助将不胜感激。

它是用 Coffeescript 写的

configuration = (RestangularProvider, $logProvider, growlProvider, IdleProvider, KeepaliveProvider) ->
  .
  .
  .
  return

configuration.$inject = [
  'RestangularProvider'
  '$logProvider'
  'growlProvider'
  'IdleProvider'
  'KeepaliveProvider'
]

angular
  .module 'vssApp.config', [
    'restangular'
  ]
  .config configuration

编辑

在尝试在我的本地机器上复制问题时,我删除了下面数组中的'ngIdle'模块。modules这导致了相同的行为,因此我假设问题源于ngIdle此处未正确加载模块。我仍然觉得缩小可能会导致问题,但同样,我不确定为什么或如何解决它。

modules = [
  'ui.router'
  'ui.bootstrap'
  'ui.select'
  'ngAnimate'
  'ngMessages'
  'ngSanitize'
  'ngCookies'
  'smart-table'
  'angularMoment'
  'templates'
  'angular-storage'
  'angular-growl'
  'vssApp.core.auth'
  'vssApp.core.loading'
  'ngIdle'
  'cgPrompt'
  'vssApp.filters'
]

runBlock.$inject = [
  '$templateCache'
]

angular
  .module 'vssApp.core', modules
  .run runBlock

编辑 2

这是我收到的错误消息的完整输出

Error: [$injector:modulerr] Failed to instantiate module vssApp due to:
Error: [$injector:modulerr] Failed to instantiate module vssApp.config due to:
Error: [$injector:unpr] Unknown provider: IdleProvider
http://errors.angularjs.org/1.3.16/$injector/unpr?p0=IdleProvider
    at https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:3:18814
    at https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:16489
    at getService (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:14903)
    at Object.invoke (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:15466)
    at runInvokeQueue (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:13793)
    at https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:14062
    at forEach (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:3:19482)
    at loadModules (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:13587)
    at https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:13964
    at forEach (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:3:19482)
http://errors.angularjs.org/1.3.16/$injector/modulerr?p0=vssApp.config&p1=E…net%2Fassets%2Fapplication-85a5fd382c73380bf2a71b66e581c941.js%3A3%3A19482)
    at https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:3:18814
    at https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:14406
    at forEach (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:3:19482)
    at loadModules (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:13587)
    at https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:13964
    at forEach (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:3:19482)
    at loadModules (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:13587)
    at createInjector (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:4:16844)
    at doBootstrap (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:3:28466)
    at bootstrap (https://SERVER/assets/application-85a5fd382c73380bf2a71b66e581c941.js:3:28995)
http://errors.angularjs.org/1.3.16/$injector/modulerr?p0=vssApp&p1=Error%3A…net%2Fassets%2Fapplication-85a5fd382c73380bf2a71b66e581c941.js%3A3%3A28995)
4

2 回答 2

0

经验法则是在每个使用模块的地方加载模块依赖项。这允许将它们解耦。这消除了服务提供者注入的竞争条件。

如果应用看起来像这样

angular.module('vssApp', ['vssApp.config', 'ngIdle', ...])..
angular.module('vssApp.config', ['restangular'])...

加载模块Idle时未定义服务的服务提供者。vssApp.config

虽然这

angular.module('vssApp', ['ngIdle', 'vssApp.config', ...])
angular.module('vssApp.config', ['restangular'])...

避免竞争条件,但仍然表明代码异味。

它应该是

angular.module('vssApp.config', ['restangular', 'ngIdle'])...

此问题仅适用于服务提供商和配置阶段。可以为任何模块顺序注入服务实例。

于 2016-06-22T13:20:46.887 回答
0

终于找到了这个问题的原因和解决办法,好像一直是bower问题。

它是一个 Rails 应用程序,所以我ng-idle 1.2.1bower.json文件中指定了,但由于某种原因,当使用 Dokku 部署应用程序时忽略了 bower 文件,并且保留了最后安装的版本0.3.5,这意味着1.0.0 ng-idle仍然使用 pre-services 命名约定。服务名称以$. 这导致了Unknown provider: IdleProvider错误,因为$IdleProvider它是实际的服务名称。

最后,我必须连接到 docker 容器并删除并重新安装所有 Bower 组件。由于某种原因,作为部署的一部分运行bower update是不够的。当我有更多时间时,我会调查导致这种行为的原因,我会在这里报告。

于 2016-06-28T16:01:28.697 回答