requirejs/require-cs

Deep dependency in webworkers could not be solved correctly

Closed this issue · 3 comments

Check with below demo and the code:

From line 17 to line 23, I add cases one by one to increase the complexity, and the cases failed from the fifth.

In summary,

  • All modules are downloaded by browser
  • If a module referenced by the first layer and the module do not dependent with others, it will be work.
  • If a module referenced by the first layer and the module dependent with others, the other module will be a null value in the scope, and then the program failed

It might be some kind of scoping problem, I think.

Ah, I believe the problem is that you are naming your cs-loaded modules. One of the restrictions when using the cs loader plugin is that it only works for anonymous modules. So instead of doing this:

define 'cs!/wahlque/ode/euler', ['exports', 'cs!/wahlque/geometry/vector' ], (e, v) ->

do this:

define ['exports', 'cs!/wahlque/geometry/vector' ], (e, v) ->

In general, anonymous modules are a better design choice too, allows for referencing modules by a different name/easier to move the files around.

Also, a side note, if you are asking for 'exports', then you do not need to return that exports value at the end of the function, it is already being tracked by the loader. Only need to return a value from the function if not using exports.prop = assignment, and in that case you do not need to ask for the exports object.

Oh, unless coffeescript always returns a value? you can just use undefined if you want. Anyway it is not a big deal.

Yes, I verified your suggestion. After remove the naming part from the definition, all modules are worked.

But about the return value, if I remove "exports" from the tail of the program, it always failed for no-finding of the specific method.

Makes sense, I think CoffeeScript returns whatever the last line returns, so the return of exports seems like it needs to be there.