Search code examples
javascriptrequirejsamd

Require.js Loads Dependency from Wrong Path


With the following Require.js config, loading moduledep from within module is fetching the dependency from the root (/moduledep.js) of the app rather than the mapped path (/assets/path/module/moduledep.js).

require.config({
  paths: {
    "module": "assets/path/module"
  },

  map: {
    "module": {
      "moduledep": "assets/path/module/moduledep"
    }
  }
});

Is there any reason that require would be ignoring the mapped path?


Solution

  • It looks like that functionality has its limitations.

    From the docs:

    This feature only works well for scripts that are real AMD modules that call define() and register as anonymous modules. Also, only use absolute module IDs for map config. Relative IDs (like '../some/thing') do not work.