R.js optimmiser is not loading all dependencies
<p>I am trying to optimise a require.js application. The application is written using Durandal and we are accessing r.js via the gulp-durandal plugin (this is just a wrapper around r.js with suitable defaults for building a Durandal application in gulp).</p>

<p>When I run the gulp task on my local machine, everything works fine. However, when we try to run the exact same gulp task on our build server (Team City) the build fails. No error is thrown during the build and it appears to be successful, but the resulting js file is two thirds of the locallly built version with some files missing.</p>

<p>When I switch on logging in r.js it appears that the task on the build server isn't pulling in the correct dependencies. For example, in my main.js in my first define call I bring in 'bindings/bindings', which points to a list of imports</p>

<pre><code>define(["require", "exports", './validationOnChange', './sortCode',       './currency', './maskedAccountNumber', './showInfo', './scrollTo', './validation', './slideDown', './datepicker', './numericInput', './date', './command', 'bindings/worldPay', './collapse'], function (require, exports) {
"use strict";
</code></pre>

<p>});</p>

<p>An example of one of these imports is</p>

<pre><code>define(["require", "exports", 'knockout', 'moment'], function (require, exports, ko, moment) {
"use strict";
ko.bindingHandlers['date'] = {
    init: function (element, valueAccessor, allBindingsAccessor) {
        var val = ko.unwrap(valueAccessor());
        if (val) {
            $(element).html(moment(val).format('DD/MM/YYYY'));
        }
    }
};
</code></pre>

<p>});</p>

<p>In the working local task, all these files are imported along with their dependencies. For example, the above file will pull in moment into the build; moment is not in the default app file but is specified in the paths of the requirejs config. When the same task is run on the build server the above file is included, but not moment. When I then try to run the built file there is an error that the module wasn't found (that is, the module shown above isn't found although I can see it in the file).</p>

<p>According to the r.js logs the build process on my local machine loads up main.js and then walks the dependency tree bringing in files as required. It then brings in any files underneath the default app directory which haven't already been loaded. </p>

<p>However, on the server, r.js loads the main.js file and it's explicit dependencies, but doesn't then continue through the dependency chain, but instead just goes straight to loading all files underneath the app folder. </p>

<p>I've tried various configurations, with or without almond, with or without uglify, removed any exclusions, relative path, absolute path, setting findNestedDependencies to true, and explicitly loading main.js with insertRequire, but no joy. Does anyone know what could cause this?</p>

<p>Thanks for any help.</p>