Skip to content

Instantly share code, notes, and snippets.

@fidian
Last active February 24, 2017 17:43
Show Gist options
  • Save fidian/003572876a1e4991e47b31b71c1ca6b2 to your computer and use it in GitHub Desktop.
Save fidian/003572876a1e4991e47b31b71c1ca6b2 to your computer and use it in GitHub Desktop.
Are you getting a totally unhelpful message from Angular saying it has a problem loading a module?
/**
* There's times that Angular reports errors similar to this one:
*
* Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.6.2/$injector/modulerr?p0=...
*
* The link doesn't explain the module tree that's being loaded nor really
* where the problem resides. :-(
*
* So I have had a bugger of a time figuring out what dependency fails and
* exactly how that module is required. This function will do that search
* for you. Simply open up the browser's console, copy and paste in the function,
* then call it with the name of the module you expect to run.
*
* Sample:
*
* checkAngularModuleDependencies("app")
*
* Results are written to console.
*/
function checkAngularModuleDependencies(name, parent) {
try {
if (angular.module(name).requires.every(function (child) {
return checkAngularModuleDependencies(child, name);
})) {
if (! parent) {
console.log("All modules seem loadable.");
}
return true;
}
console.error(" ... included by " + name);
} catch (e) {
console.error("Unable to find module " + name);
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment