Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

module not loaded yet for context

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'); 
like image 453
Sneaky Wombat Avatar asked Jan 12 '13 03:01

Sneaky Wombat


2 Answers

Even with the "traditional" or non-sugar method (http://requirejs.org/docs/whyamd.html#sugar), this error persisted. It turned out that there was a circular import that I accidentally introduced into the codebase during a refactor. Removing that circular import removed this error.

like image 128
Sneaky Wombat Avatar answered Sep 18 '22 00:09

Sneaky Wombat


Change it to

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

    // ...
});
like image 39
Eugene Naydenov Avatar answered Sep 22 '22 00:09

Eugene Naydenov