Angular failed to instantiate modules in production build
<p>I'm trying to add features requiring new third party modules to an Angular app, using gulp and bower. Everything is fine in dev mode but any new modules I add produce the notorious <code>"Failed to instantiate module"</code> error in production. I have tried disabling the uglify build step and it made no difference. Simply declaring the new module as a dependency to one of my own is enough to produce the error.</p>

<p>Unlike in many of these questions I am already using the string array syntax for dependencies and the app is already functioning with various other modules. I see no difference between what I'm adding and the other libraries already in use.</p>

<p>Here is my current attempt at including <code>ngCookies</code>, but I've done the same thing with others eg. <code>ngFileUpload</code> with the same results.</p>

<p><strong>bower.json:</strong></p>

<pre><code>  "dependencies": {
    "jquery": "^2.1.4",
    "angular": "^1.5.9",
    "angular-sanitize": "^1.4.5",
    "extras.angular.plus": "^0.9.2",
    "moment": "^2.10.3",
    "angular-ui-router": "^0.2.15",
    ...
    "angular-cookies": "^1.5.9", // new
  },
</code></pre>

<p><strong>index.html:</strong></p>

<pre><code>&lt;!-- build:js js/lib.js --&gt;
&lt;!-- bower:js --&gt;
&lt;script src="/bower_components/jquery/dist/jquery.js"&gt;&lt;/script&gt;
&lt;script src="/bower_components/angular/angular.js"&gt;&lt;/script&gt;
&lt;script src="/bower_components/angular-sanitize/angular-sanitize.js"&gt;&lt;/script&gt;
&lt;script src="/bower_components/extras.angular.plus/ngplus-overlay.js"&gt;&lt;/script&gt;
&lt;script src="/bower_components/moment/moment.js"&gt;&lt;/script&gt;
&lt;script src="/bower_components/angular-ui-router/release/angular-ui-router.js"&gt;&lt;/script&gt;
...
&lt;script src="/bower_components/angular-cookies/angular-cookies.js"&gt;&lt;/script&gt; // new
&lt;!-- endbower --&gt;
&lt;!-- endbuild --&gt;
</code></pre>

<p><strong>core module declaration:</strong></p>

<pre><code>(function () {
  'use strict';

  angular
    .module('app.core', [
      'ngAnimate',
      'ngSanitize',
      'blocks.exception',
      'blocks.logger',
      'blocks.router',
      'ui.router',
      'firebase',
      'ngMap',
      'ngplus',
      'ngCookies', // new
    ]);

})();
</code></pre>

<p><strong>minified/uglified js output:</strong></p>

<p>app.js</p>

<pre><code>function(){"use strict";angular.module("app.core",["ngAnimate","ngSanitize","blocks.exception","blocks.logger","blocks.router","ui.router","firebase","ngMap","ngplus","ngCookies"])}(), ...
</code></pre>

<p>lib.js</p>

<pre><code>t.module("ngCookies",["ng"]).provider("$cookies", ... 
</code></pre>

<p><strong>console output:</strong></p>

<pre><code>Error: [$injector:modulerr] Failed to instantiate module app due to:
[$injector:modulerr] Failed to instantiate module app.core due to:
[$injector:modulerr] Failed to instantiate module ngCookies due to:
[$injector:nomod] Module 'ngCookies' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.5.9/$injector/nomod?p0=ngCookies
</code></pre>