6

Quick question... I have a define for requirejs setup like so... it works about 8-10% of the time. It seems that a resource sometime isn't loaded in time. Can I wrap the above var require list in a way that ensures the code below it will run correctly? The error I get when it doesn't work is this:

Uncaught Error: Module name "views/association/Associations" has not been loaded yet for context: _

define(function( require ){
  // requirejs - too many includes to pass in the array
  var $ = require('jquery'),
      _ = require('underscore'),
      Backbone = require('backbone'),
      namespace = require('namespace'),
      // models
      CustomerModel = require('models/customer/customer'),
      // collections
      // views
      BaseView = require('views/baseView'),
      Auth = require('views/auth/Auth'),
      SideNav = require('views/sidenav/SideNav'),
      CustomersView = require('views/customer/Customers'),
      AssociationsView = require('views/association/Associations'),
      //CustomerListCpeView = require('views/customer/CustomerListCpe'),
      //CustomerAddCpeView = require('views/customer/CustomerAddCpe'),
      // templates
      CustomerDetailTemplate = require('text!templates/customer/customerDetail.html'); 
4

2 回答 2

7

即使使用“传统”或非糖方法 (http://requirejs.org/docs/whyamd.html#sugar),此错误仍然存​​在。事实证明,我在重构期间不小心将循环导入引入了代码库。删除该循环导入删除了此错误。

于 2013-01-26T21:47:40.537 回答
3

将其更改为

define([
    'jquery',
    'underscore',
    'backbone',
    // ...
    'views/association/Associations'
    // ...
], function($, _, Backbone, /* ..., */ AssociationsView) {

    // ...
});
于 2013-01-12T03:55:44.630 回答