模块尚未加载上下文

时间:2013-01-12 03:19:36

标签: javascript node.js requirejs

快速提问...我有一个如此定义的requirejs设置......它的工作时间约占8-10%。似乎资源有时没有及时加载。我可以以确保其下方代码正确运行的方式包装上面的var require列表吗?我无法解决的错误是:

未捕获错误:尚未为上下文加载模块名称“views / association / Associations”:_

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'); 

2 个答案:

答案 0 :(得分:7)

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

答案 1 :(得分:3)

将其更改为

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

    // ...
});