4

I have server logs that show a client is loading all of the modules required in my ng-app = M declaration attached to the <html> element. Meaning, all of the dependencies seem to be loaded correctly before my app is declared and initialized.

My app looks like this:

var app = angular.module('M', ["ui.router",'ui.bootstrap','angular.media','chart.js','ngMessages','ngTouch']);

The module reported to my server as the cause of the Module Unavailable error is angular.media even though I can see the following in the server log:

XX.XX.X.XXX - - [13/Dec/2017:19:31:24 +0000] "GET /getScript/angular-media.js?v=7.1.7 HTTP/1.1" 200 5172 "https://example.com/home" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.78.2 (KHTML, like Gecko) Version/6.1.6 Safari/537.78.2"
XX.XX.X.XXX - - [13/Dec/2017:19:31:25 +0000] "GET /getScript/authapp.js?v=9.2 HTTP/1.1" 200 1449 "https://example.com/home" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.78.2 (KHTML, like Gecko) Version/6.1.6 Safari/537.78.2"

I believe the error might have to do with the fact that angular.media relies on ui.router as well, which may be causing the issue? The ui.router is loaded from the cache before reaching the /home page.

angular.module('angular.media', ["ui.router"])

What is causing this issue do you think?

I can load the page fine so I am relying on reported errors to my server from this user but wondering if it is a problem with how I am doing Angular dependency injection.

Angular Url Error: HERE

First 10 lines of Angular Media:

angular.module('angular.media', ["ui.router"])
.controller('Controller', ['$scope', function($scope) {
}])
.directive('angularmedia', [
           '$angularMediaStack',
  function($mediaStack) { 
  return {
    restrict: 'A',
  template:'<div class="someClass"><angularmediabar></angularmediabar><div class="earParagraph"><rewind></rewind><play></play><fastforward></fastforward></div></div>',
controller: function($scope, $element,$attrs) {

I am wondering if there is a better way I could be logging and debugging this, since I can't reproduce on my own implementation.

Since the server log indicates the script is being loaded, is it something with how I am trying to record the client-side error? I am using this code:

window.onerror = function (message, url, lineNo) {
    try { 
        var request = new XMLHttpRequest();
        var formData = new FormData();
         formData.append("message", message);
         formData.append("url", url);
         formData.append("line", lineNo);
       request.open("POST", "/errors");
       request.send(formData);
    } catch (s) {}
    return true;
};

Furthermore: this is the order of the script load on /home

    <script src="https://example.com/js/jquery.min.js"></script>
    <script src="https://example.com/js/bootstrap.min.js"></script>
    <script src="https://example.com/js/jquery.scrollex.min.js"></script>
    <script src="https://example.com/js/jquery.transit.min.js"></script>
    <script src="https://example.com/js/angular.min.js"></script>
    <script src="https://example.com/js/angular-animate.min.js"></script>
    <script src="https://example.com/js/ui-bootstrap.min.js"></script>
    <script src="https://example.com/js/angular-ui-router.min.js"></script>
    <script src="/js/angular-messages.js"></script>
    <script src="/js/angular-touch.js"></script>
    <script src="/getScript/angular-media.js?v=7.1.7"></script>
    <script src="/getScript/Chart.js"></script>
    <script src="/getScript/angular-chart.js"></script>
    <script src="/getScript/moment.js"></script>
    <script src="/getScript/owl.carousel.min.js"></script>
    <!--HTML Content-->
    <script src="/getScript/authapp.js?v=9.2"></script>
    <script src="/getScript/authconfig.js?v=9.2"></script>
    <script src="/getScript/authservices.js?v=9.2"></script>
    <script src="/getScript/authdirectives.js?v=9.2"></script>
    <script src="/getScript/authcontrollers.js?v=9.2.9.2"></script>
    <script>
    app.factory('AboutMe', [function() {
    //fill with PHP derived values
    }]);
</script>

The user loads ui.router from the landing page and it stays in the cache. Then the IP changes, they go to the homepage, and the error as I have stated Module Unavailable (angular.media) is reported to my server using the reporting code I gave above.

Again, I cannot reproduce this error myself and it happens occasionally to various users at different times (never more than one or two at a time) before resolving itself, but it is becoming a big pain.

Please advise as to what could be causing this or how I can better reproduce.

Summer Developer
  • 2,056
  • 7
  • 31
  • 68
  • Angular errors usually have a URL link back to the angular home page to help troubleshoot. Can/Will you post that link? – gh9 Dec 13 '17 at 21:33
  • @gh9 Thank you! See edit where I included it! – Summer Developer Dec 14 '17 at 00:15
  • From my googling there doesnt appear to be an Angular.media module. Will you put the first 10 lines of code from the angular-media file in the question? – gh9 Dec 14 '17 at 14:37
  • @gh9 It is my own module, thank you so much for your help! Posting now! – Summer Developer Dec 14 '17 at 18:19
  • Long shot but, do you have your angular.media script referenced before you bootstrap your angular app? – gh9 Dec 14 '17 at 18:28
  • @gh9 What do you mean? I don't think so. It's not a dependency of any other module if that's what you mean by "referenced". – Summer Developer Dec 14 '17 at 19:34
  • Just making sure that you have all your scripts loading before you app.js script. – gh9 Dec 14 '17 at 19:54
  • @gh9 yes I do load all the modules/dependencies before app.js – Summer Developer Dec 15 '17 at 01:26
  • @SummerDeveloper you can add delay to some scripts [PHP - Sleep](http://php.net/manual/en/function.sleep.php) for reproduce the error (change to php script to get js) – jd_7 Dec 20 '17 at 23:01
  • 1
    What if you minify and combine all those scripts into single one? That you can be certain that all scripts have loaded, because there is only one big javascript file ... – David Votrubec Dec 22 '17 at 11:33
  • If you are using the example domain URL in your application as well, please make sure that they are stable. When I tried the example domain URL (https://example.com/js/angular-ui-router.min.js) they don't return any response. When no response is returned, angular won't have any modules to load. Hence you would have got this error. Check [plnkr]: https://plnkr.co/edit/WEiuZ2Zamihx0YQP1BD9?p=info – Vijayarajan Ravindran Dec 22 '17 at 16:58

0 Answers0