RequireJS构建错误[RangeError:超出最大调用堆栈大小]

时间:2014-08-20 08:22:10

标签: javascript backbone.js requirejs gruntjs bower

我正在尝试使用requirejs:production任务构建我的Grunt / RequireJS应用程序,并且我得到以下输出:

Running "requirejs:production" (requirejs) task
>> Tracing dependencies for: ../bower_components/almond/almond
>> RangeError: Maximum call stack size exceeded
>> In module tree:
>>     main
>>       models/session
>>         views/root
>>           navigation
>>             permissions
>>               text
{ [Error: RangeError: Maximum call stack size exceeded
In module tree:
    main
      models/session
        views/root
          navigation
            permissions
              text
]
  originalError:
   { [RangeError: Maximum call stack size exceeded]
     moduleTree:
      [ 'text',
        'permissions',
        'navigation',
        'views/root',
        'models/session',
        'main' ],
     fileName: '/Users/zensavona/softwaredev/projects/haze/t3-web/web-admin/src/main/bower_components/text/text.js' } }

我认为它所谈论的代码是:

define(["backbone", "models/permissions", "text!/ducks/api/Permissions/Current"],
  function(Backbone, Permissions, permissionJSON) {
    if (permissionJSON.indexOf("<center><h2>Login</h2></center>") > -1) {
      return new Permissions();
    } else {
      var data = JSON.parse(permissionJSON);
      return new Permissions(data);
  }
});

我的第一直觉是某种循环依赖(?)但我看不到。这与我的代码或text模块有关吗?

2 个答案:

答案 0 :(得分:1)

我遇到了requireJS 2.1.15的这个问题。问题似乎是html扩展不是路径的一部分。

define([
    ...
    'text!templates/user/elements/profile.moderate.menu' //.html extension is missing
]...

一旦我添加了扩展程序

,事情就开始了
define([
    ...
    'text!templates/user/elements/profile.moderate.menu.html'
]...

答案 1 :(得分:0)

FWIW,我无法解决这个问题并通过一起删除text来修复它。幸运的是,这是我需要它的唯一地方,我用async: false jQuery调用替换它(见下文)。

define(["jquery", "backbone", "models/permissions"],
  function($, Backbone, Permissions) {
    var permissionJSON = "";
    $.ajax({
        type: "GET",
        url: '/ducks/api/Permissions/Current',
        async: false,
        success: function(data) {
          permissionJSON = data;
        }
    });

    if (permissionJSON.indexOf("<center><h2>Login</h2></center>") > -1) {
      return new Permissions();
    } else {
      return new Permissions(permissionJSON);
    }
});