1
Vote

datajs-$VER.js defines two named AMD modules

description

Code as of datajs 1.1.2:
    // AMD support
    if (typeof define === 'function' && define.amd) {
        define('datajs', datajs);
        define('OData', odata);
    } else {
        window.datajs = datajs;
        window.OData = odata;
    }
Relevant AMD/RequireJS documentation:
Only one module should be defined per JavaScript file, given the nature of the module name-to-file-path lookup algorithm. Multiple modules will be grouped into optimized files by the optimization tool, but you should only use the optimization tool to place more than one module in a file.
Source: http://requirejs.org/docs/api.html#modulenotes
These [names] are normally generated by the optimization tool. You can explicitly name modules yourself, but it makes the modules less portable -- if you move the file to another directory you will need to change the name. It is normally best to avoid coding in a name for the module and just let the optimization tool burn in the module names. The optimization tool needs to add the names so that more than one module can be bundled in a file, to allow for faster loading in the browser.
Source: http://requirejs.org/docs/api.html#modulename

Suggestions (alternatives):
  1. Split build target into two files: datajs-$VER.js and datajs-odata-$VER.js.
  2. Define a single module that references both objects and let users re-assign themselves if they want to. Example.

comments

tnelis wrote Feb 4, 2014 at 12:56 PM

Note: To anyone who wishes to workaround the issue for the time being, the proper way is probably to use RequireJS bundles:
bundles: {
    "path/to/datajs-$VER": ["datajs", "OData"]
}
When running a RequireJS version below 2.1.10 (bundles not supported), using paths also works:
paths: {
    datajs: 'path/to/datajs-$VER',
    OData: 'path/to/datajs-$VER'
}
Credits to Louis at Stack Overflow. More information here.