【问题标题】:Breeze with durandal causing 'module not loaded undefined is not a function' error微风与 durandal 导致“模块未加载未定义不是函数”错误
【发布时间】:2014-12-10 10:47:57
【问题描述】:

加载我的支付模块时,我收到“无法加载路由模块(支付)”。未定义不是函数的错误。我已经尝试了一切,甚至将其回滚到一周前发生的一些提交,并且不断收到相同的错误。经过大量故障排除后,我将其追溯到我的数据服务。我发现当我在我的数据服务中删除所有对“微风”的引用时,它会按预期加载(当然,它不起作用)。如果我将 'breeze' 添加回 'define' 依赖数组,我会得到 undefined is not a function 错误。

我没有更改要求。 config,但我已将它与我的数据服务的定义语句一起粘贴在下面。

require.config({
    paths: {
        'ko': '../Scripts/knockout-3.1.0',
        'breeze': '../Scripts/breeze.debug',
        'jquery': '../Scripts/jquery-2.1.1',
        'jquery-ui': '../Scripts/jquery-ui-1.11.2',
        'bootstrap': '../Scripts/bootstrap.min',
        'text': '../Scripts/text',
        'require': '../Scripts/require',

        // JS Object Serializer/deserializer.  Handled cyclic objects, efficient stringifying.
        'JSOG': '../Scripts/JSOG',
        'domReady': '../Scripts/domReady',
        'Q': '../Scripts/q',

        // Notifications
        'toastr': '../Scripts/toastr',

        //Durandal
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'transitions': '../Scripts/durandal/transitions',

        // Lazy-developer date formatting
        'moment': '../Scripts/moment.min'
    },
    map: {
        '*': { 'knockout': 'ko' } // Necessary for Durandal, expects Knockout to be 'knockout', not 'ko'
        //                           Breeze expects 'ko'??
    },
    shim: {
        'bootstrap': {
            deps: ['jquery'], // don't load the bootstrap.js until jquery is loaded
            exports: 'bootstrap'
        },
        'JSOG': {
            exports: 'JSOG'
        }
    }

以及我对数据服务的定义声明:

define(['ko', 'breeze', 'logger', 'Q', 'constants', 'JSOG'], function (ko,breeze,logger,Q,c,JSOG) {

请帮忙。我敢肯定这很简单,但我一直在扯头发。

编辑:根据 Jeremy 的要求,这是堆栈跟踪:

TypeError: undefined is not a function
at proto.initialize     (http://localhost:62418/Scripts/breeze.debug.js:15785:26)
at initializeAdapterInstanceCore (http://localhost:62418/Scripts/breeze.debug.js:1870:14)
at Object.__config.getAdapterInstance (http://localhost:62418/Scripts/breeze.debug.js:1818:14)
at breeze.AbstractDataServiceAdapter.proto.initialize (http://localhost:62418/Scripts/breeze.debug.js:15437:30)
at initializeAdapterInstanceCore (http://localhost:62418/Scripts/breeze.debug.js:1870:14)
at __config.initializeAdapterInstance (http://localhost:62418/Scripts/breeze.debug.js:1791:12)↵    at __objectMap (http://localhost:62418/Scripts/breeze.debug.js:56:27)
at Object.__config.initializeAdapterInstances (http://localhost:62418/Scripts/breeze.debug.js:1765:12)
at http://localhost:62418/Scripts/breeze.debug.js:17358:15
at def (http://localhost:62418/Scripts/breeze.debug.js:10:34)"

即使我重构并摆脱 Durandal 和 Require js,错误似乎也会发生。即使已加载 Jquery(连同 KO 和 Q),我在 var $injector = ng.injector(['ng']); 处收到错误,显然它正在尝试加载 angular ajax 调用,即使未定义 angular。

【问题讨论】:

  • “未定义不是函数”错误的调用堆栈是什么?
  • @Jeremy,再次救援。我目前没有校准堆栈——我已经重构了应用程序以摆脱 Durandal 和 RequireJS,但我仍然收到错误消息。看起来微风正在尝试加载角度注入器(第 15785 行` var $injector = ng.injector(['ng'])) which doesn't exist. If I travel back up through the call stack, I find the line 15437 (ajaxImpl = blink.config.getAdapterInstance("ajax");`) 似乎是错误的实际原因——它永远不会到达代码的下一行,而是在某个地方被分流以抛出所提到的错误。
  • k- 我的下意识反应是放弃角度。 Angular 2.0 是一个完全重写的版本,所以如果你想让你的应用程序保持最新状态,你需要进行相当多的重构。此外,Durandal 非常适合 SPA 应用程序。罗伯·艾森伯格就是那个人。 eisenbergeffect.bluespire.com/leaving-angular
  • 我想你是在告诉我,我不应该使用 angular,而应该使用 Durandal,但事实就是如此——我没有使用 angular。我认为由于某种原因,微风没有看到 jquery,而是尝试使用 angular。我不知道为什么会这样。
  • @Jeremy,我想通了。浪费了一天,但我很高兴它在我身后。谢谢你的帮助,也谢谢你的链接——我不知道 Eisenberg 和 Angular 已经分道扬镳了。我一直担心 Durandal 路线(因为预计的角会聚),但现在它可能会更有意义。

标签: breeze durandal-2.0


【解决方案1】:

看来我想通了。我也在 AngularJS 中做一些开发工作,很多个月前我为 Chrome 安装了 AngularJS Batarang 扩展。我有一段时间没用了,所以我忘了它。我禁用了它,关闭并重新打开了浏览器——Walla! -- 一切都恢复正常了。

我猜微风以某种方式检测到 angular 已加载到扩展中,然后尝试加载 $http,但它无法访问,一切都崩溃了。我不知道为什么它昨天才开始发生(也许它已被禁用并且以某种方式再次意外启用)但这就是问题所在。我可以让错误发生或随意消失。

【讨论】:

  • 他们在最后一两天发布了 Batarang 的更新,从那以后它对每个人都造成了严重破坏。得知 Batarang 引入了 Angular 的副本,我不会感到惊讶,Breeze 看到了它并感到困惑。我们没有尝试在加载 KO 和 Ng 的情况下测试 Breeze,因为这不太可能发生(礼貌地说)。
猜你喜欢
  • 2013-06-06
  • 2014-12-15
  • 1970-01-01
  • 1970-01-01
  • 2015-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多