【问题标题】:Embedded AngularJS App and RequireJS/AMD error [duplicate]嵌入式 AngularJS 应用程序和 RequireJS/AMD 错误 [重复]
【发布时间】:2016-07-11 07:04:42
【问题描述】:

我有一个 AngularJS 应用程序,它在现有网站中使用。

类似这样的:

<div ng-app="configurator" ng-controller="SomeController as someController" data-auth="some-jwt-token" class="app-wrapp">...</div>

该网站正在使用 requireJS 来处理他们的 JavaScript 内容。这就是我的应用因以下错误而中断的地方:

mnty.1464947369.js:65 Uncaught Error: Mismatched anonymous define() module: function (){return factory()}
http://requirejs.org/docs/errors.html#mismatchmakeError @ mnty.1464947369.js:65v @ mnty.1464947369.js:65o @ mnty.1464947369.js:65requirejs @ mnty.1464947369.js:65(anonymous function) @ mnty.1464947369.js:70fetchPlugins @ mnty.1464947369.js:70process @ mnty.1464947369.js:70mount @ mnty.1464947369.js:70(anonymous function) @ main_3-21-6.js:149u @ mnty.1464947369.js:66fireWith @ mnty.1464947369.js:66ready @ mnty.1464947369.js:66a @ mnty.1464947369.js:65
app-bundled.js:6 Uncaught Error: [$injector:modulerr] Failed to instantiate module configurator due to:
Error: [$injector:modulerr] Failed to instantiate module rzModule due to:
Error: [$injector:nomod] Module 'rzModule' 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.5.5/$injector/nomod?p0=rzModule

一些使用过的模块在其构建中使用 UMD,但大多数不是。这是我认为的关键问题。我该如何解决这个问题?

(AngularJS 应用程序捆绑在单个 JS 文件中,并包含在页面的页脚中)

【问题讨论】:

  • 能否给我们看看你的配置js文件的代码??
  • 这个问题写得很糟糕。有多个错误是由不同的问题引起的。我已经关闭了一个处理您的第一条错误消息(“不匹配的匿名定义”)的问题,请在您的问题中包含 minimal reproducible example,然后我们可以重新打开。目前,缺少 MCVE 导致您得到 3 个未解决问题的答案。

标签: javascript html angularjs requirejs single-page-application


【解决方案1】:

我认为问题在于模块的加载顺序,如您在此处看到的:

Error: [$injector:nomod] Module 'rzModule' is not available! You either misspelled the module name or forgot to load it.

在加载 configurator 模块之前,请检查该模块是否已加载到 Angular 中。

【讨论】:

  • 该模块包含UMD,所以它使用requireJS而不是全局angularJS加载器,因此angularjs不知道它。这是我的问题。
  • 嗯,我明白了,那么您可以在创建模块之前要求 rzModule 吗?另外,你能分享一下 repo 或者这个 rzModule 来自哪里?
【解决方案2】:

您正在使用ng-app="configurator" 并显示错误

Error: [$injector:nomod] Module 'rzModule' is not available! You either misspelled the module name or forgot to load it.

所以模块名称应该相同。

【讨论】:

  • rzModule 是配置器的依赖
【解决方案3】:

我必须同意 6uitar6reat6od 和 Durgpal Singh,你可能还有一个带有 define 方法的 JS 文件,它与 require js 冲突,要解决这个问题,你需要在你的 require 配置部分正确配置这个文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 2011-01-24
    • 2018-03-17
    • 1970-01-01
    • 2016-08-04
    • 2017-04-24
    相关资源
    最近更新 更多