dependencies are undefined

Showing 1-12 of 12 messages
dependencies are undefined Steve Beer 8/13/12 2:03 AM
The issue is also described here: http://stackoverflow.com/questions/10959095/intermittent-requirejs-load-error

The problem occurs mostly in Firefox for me. In Chromium the whole thing works in 90% of the cases. Can this be a require.js issue?

regards,
Stefan
Re: [requirejs] dependencies are undefined James Burke 8/13/12 1:04 PM
Without specific details, this normally means that a dependency is not
being properly expressed for a module, it may be assuming a
dependency. Also note that requirejs does not guarantee a load order
across a list of dependencies.

If using shim config, then it may mean that one of the shimmed
libraries does not have all of its dependencies listed in the shim
config.

James
Re: [requirejs] dependencies are undefined Steve Beer 8/13/12 11:09 PM
But how can it be sometimes working in Chromium if something's lacking a dependency?
Actually, my code looks like this:

// tableView.js

(function () {
  "use strict";

  define([
    'jquery',
    'backbone'
  ], function ($, Backbone) {
    var TableView = Backbone.View.extend({
      initialize: function () {
        this.collection.on("add change remove reset", this.render, this);
      },
      render: function () {
        var that = this, rowView, listEl;

        this.$el.html(this.template());
        listEl = this.$('tbody');
        this.collection.each(function (model, i) {
          if (i === 0) {
            listEl.empty();
          }
          rowView = new that.rowView({ model: model });
          listEl.append(rowView.render().el);
        });
        return this;
      }
    });
    Backbone.TableView = TableView;
    return TableView;
  });

}());

// buildingList.js

(function () {
  "use strict";

  define([
    'jquery',
    'backbone',
    'tableView',
    'text!../templates/box/buildingList.html',
    'buildingRow'
  ], function ($, Backbone, TableView, tpl, BuildingRow) {
    /**
     * The View to show the Buildings collection
     * */
    var BuildingList = Backbone.TableView.extend({
      template: _.template(tpl),
      rowView: BuildingRow
    });
    return BuildingList;
  });
}());

// buildingRow.js

(function () {
  "use strict";

  define([
    'jquery',
    'backbone',
    'text!../templates/box/buildingRow.html',
    'require'
  ], function ($, Backbone, tpl, require) {
    var buildingRow = Backbone.View.extend({
      tagName: "tr",
      template: _.template(tpl),
      events: {
        "click td": "itemClick"
      },
      render: function () {
        this.$el.html(this.template({ building: this.model.toJSON() }));
        return this;
      },
      itemClick: function () {
        // calling require instead of using usual dependency
        // is a workaround because this is a circular dependency
        require("box").navigate("//box/buildings/" + this.model.toJSON()._id, true);
      }
    });
    return buildingRow;
  });
}());

Router instantiates a buildingList, which inherits from tableView and instatiates some buildingRows.
If i remove the 'text!..templates/box/xxxxx.html' dependencies and give empty strings to _.template instead, no error is thrown anymore.

Stefan
Re: [requirejs] dependencies are undefined James Burke 8/14/12 10:36 AM
It depends on network fetch speed, execution order and cache.

For the code sample below, what backbone are you using? If it is the
regular one from documentcloud/backbone, then you will need to have a
shim config set up for it:

http://requirejs.org/docs/api.html#config-shim

requirejs.config({
  shim: {
    'backbone': {
      deps: ['jquery', 'underscore'],
      exports: 'Backbone'
    }
  }
});

Also, I suggest using the latest requirejs 2.0.5 -- your mention of
removing a text dependency and having it work sounds like a bug that
was fixed in one of the early 2.0.x releases.

James
Re: [requirejs] dependencies are undefined Steve Beer 8/15/12 2:30 AM
I am using the latest requirejs, original and latest Backbone and shim config:

// app.js

  requirejs.config({
    // defines dependencies for modules that do not define them theirselves
    shim: {
      'underscore': {
        exports: '_'
      },
      'backbone': {
        deps: ['underscore', 'jquery'],
        exports: 'Backbone'
      },
      'bootstrap': {
        deps: ['jquery'],
        exports: 'bootstrap'
      },
      'deep-model': {
        deps: ['backbone'],
        exports: 'Backbone.DeepModel'
      }
    },
    // define paths to modules you don't want to write out
    paths: {
      // ...
    }
  });


That's why I opened this thread - I am simply out of ideas what could go wrong here.
I also saw this bug you mentioned. Is it possible it wasn't fixed for all cases?

greets,
Stefan
Re: [requirejs] dependencies are undefined James Burke 8/15/12 10:37 AM
If you have a test case I can try, that would help. Nothing looks
obviously wrong. Feel free to pass it to me off-list if it should be
private.

James
Re: [requirejs] dependencies are undefined Steve Beer 8/16/12 6:13 AM
I tried to create a simple example where this error happens, but I couldn't reproduce it. I think the issue occurs only for more complex applications.
I can't just send you my whole productive code because it has some more dependencies to be able to work, which I'm not allowed to send you.

I will now just try to gather the information I have:

If you have a dependency structure that looks like that:
    Router
      -> View1
          -> text!template
          -> View2
              ->text!template
several times (in my case 4 times), View1 will sometimes (in Chromium) or always (in Firefox) be just undefined when the Router tries to instantiate it after a page reload.
Several times means the Router not only depends on View1 but also on more views with the same dependency structure as View1.
Only having one view with said structure doesn't seem to trigger the error.
Removing the text-dependency of View2 is enough to avoid the error.
Using r.js to optimize the code also removes the error.

I can imagine a full test case reproducing the issue would be much better, but I am currently not able to serve one. Maybe I'll create one someday when I have more time, because this really bugs me. :)

Stefan
Re: [requirejs] dependencies are undefined James Burke 8/24/12 10:23 AM
On Fri, Aug 24, 2012 at 2:39 AM, Ludovico Fischer <livr...@gmail.com> wrote:
> I am experiencing the same issue, which is solved by removing the text!
> dependency. I might be able to supply a test case.

That would be great. Be sure to try it with requirejs 2.0.6, the
latest release, and if you get it assembled, please open a ticket here
pointing to the test case:

https://github.com/jrburke/requirejs/issues

If it should be private, feel free to send it to me directly off-list.

James
Re: [requirejs] dependencies are undefined Ludovico Fischer 8/30/12 12:53 AM
It is more complicated than I thought to produce a test case. I think that the text plugin interferes with loading other modules, the problem is that, if there are too few modules, they all get loaded fast enough and the error appears on my machine only once every thirty or thirty times. In the real application I have got more than a hundred modules, and the error appears about once every four times the page is loaded.
Re: dependencies are undefined Sergio Medina 8/31/12 10:29 AM
Did you guys have a found a solution to this?
Re: [requirejs] dependencies are undefined James Burke 8/31/12 11:36 AM
If someone can pass me an URL for me to test with instructions on what
to do, then I can do a debug session. You can send it to me privately,
off-list, if it should be a private URL.

James

On Fri, Aug 31, 2012 at 10:48 AM, Ian Lollar <ian.l...@gmail.com> wrote:
> Hey guys,
>
> I posted the Stack Overflow question Stefen linked to in his first post - I
> thought I'd join the discussion here as well.
>
> I can confirm what Ludovico said - producing a simple test case for this
> issue if really difficult. The issue seems to, by nature, only occur when a
> project gets larger. When the issue first cropped up for me, I was working
> on a steadily growing web app. In the beginning phases of app development, I
> never ran into these errors. Then, suddenly one day, my team and I started
> getting the intermittent problems.
>
> The intermittency is what makes this problem especially difficult to track
> and and reproduce.
>
> I'll see if I can get some time to take another crack at a test case - but I
> have a feeling the test case will most certainly not be small or simple.
>
> - Ian
Re: [requirejs] dependencies are undefined RAHUL BISHT 11/11/14 7:28 PM
Hi James,
I am also facing a similar issue.But mine is an angular app in which i am loading j query before kendo UI but when i press F5 key and reload the application.sometimes I saw the application hanged and if i refresh it again it works. it is giving error jquery is not defined in KendoUI library,inspite of being loaded earlier then kendo UI. I have found a post also mentioning  similar issue.


can you please help us regarding this.

thanks.