Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#14649 closed defect (invalid)

Using relative modules are assumed to be URLs by the loader

Reported by: Kitson Kelly Owned by: Rawld Gill
Priority: high Milestone: tbd
Component: Loader Version: 1.7.1
Keywords: Cc: cjolif
Blocked By: Blocking:


The AMD Loader appears to treat relative modules, when there is no reference module as URLs instead of as a module on its own. For example if the following is done:

require(["./myModule"], function(myModule){
  var myInstance = new myModule(...);

The loader will attempt to fetch myModule instead of myModule.js, but if I do the following:

require(["package/myModule"], function(myModule){
  var myInstance = new myModule(...);

The loader will attempt to fetch myModule.js.

I don't know if this is the expected behaviour, but it caused some level of confusion as per the thread here:

Change History (3)

comment:1 Changed 10 years ago by cjolif

Cc: cjolif added

comment:2 Changed 10 years ago by Rawld Gill

Resolution: invalid
Status: newclosed

Let's take the second one first:


Is just loading a normal module. If package happens to be a package, then the given package config will be used to resolve myModule's URL and perhaps apply mappings etc.; if not then paths will be used (if any). Nothing special here...just normal AMD stuff.

As for the first example:


When a relative module-id is used with global require, the behavior is undefined by the "AMD spec" (for whatever that is worth). At one point, RequireJS had the concept of assuming that an expression that was not a module-id (e.g., "./myModule" in the context of global require) would be treated as a URL. I don't know if that behavior still exists.

In any event, the dojo and bdLoad loaders treat non-module-ids as URLs...thus following the philosophy of letting the user express odd things...if they really want to do that.

comment:3 Changed 8 years ago by Sasha Firsov

Still counting as a bug. work around is to create current page path as a path mapping in HTML:

require({paths:{ currentPage:location.pathname.substring(0,location.pathname.lastIndexOf('/'))} } ,[ "currentPage/MyModule"...

Stink but works.

Note: See TracTickets for help on using tickets.