0

I am currently getting an error when loading files after the initial page load that I have managed to trace back to the Google visualization library. When I deployed this page last year, it worked fine, but when I was adding to the page now, the error began appearing. Not sure when between then and now that this error actually sprang up as this page is not used by many and none of them have reported this to me. I was able to figure out that the globalDefQueue is getting an anonymous module left in it from the initial load, which causes the future loads to error out. How do I go about solving this problem? I have seen here on SO people recommend just adding an onError override to require and leave it blank, but I'd rather not cripple the framework like that. I've tried googling and searching the chart forum itself, and I cannot see a way to properly load the library using require, which I'm hoping would solve the issue, but at the same time I have no idea if it would.

I am loading the require file and main as such: (This is my only script tag)

<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/app/lib/requirejs/require.js" data-main="<%=request.getContextPath()%>/scripts/app/src/init"></script>

init.js:

require(['domReady!', 'angular', 'jquery', 'https://www.gstatic.com/charts/loader.js', 'app'], function (document, ng, $) {
    'use strict';
    ...
    google.charts.load("current", {"packages": ["line", "corechart"]});
    google.charts.setOnLoadCallback(function () {
    ...
    });
});

Specifically it is the call to load from the charts object that adds the new item to global stack anonymously. As this is a function being called from the library, there is no way that I know of for me to circumvent its loading mechanism with RequireJS.

Louis
  • 146,715
  • 28
  • 274
  • 320
GrouchyPanda
  • 1,004
  • 8
  • 20
  • I've edited and reopened. Your title in particular was giving the wrong idea. I've removed some text that no longer made much sense without the closure notice. You should definitely check whether `google.charts.load` is adding `script` elements to the page. I would be *very* surprised if it does not because there are only a few ways to load scripts dynamically and adding `script` elements is really the best way. (This is what RequireJS does, actually.) – Louis Jun 22 '16 at 23:07
  • Well, I'm unable to reproduce the error you get... See this [plunkr](https://plnkr.co/edit/mgHvA0IqbEY3w6Uk0o9g?p=preview). If I have RequireJS just load the Google loader and use it like you did, no error. – Louis Jun 22 '16 at 23:23
  • @Louis I was finally able to track down the issue and like I thought, it exists within the google charts loader. The UMD wrapper that is being used in the webfontkit is the overall culprit. The issue still looks to be unsolved on there end. [Here](https://plnkr.co/edit/OKvCFWZaFuzlAL2dizQV?p=preview) is an update to your plunkr to show you the issue, and [here](https://github.com/typekit/webfontloader/issues/278) and [here](https://github.com/google/google-visualization-issues/issues/2070) are the issue trackers. The workaround listed doesn't work for line, so I'm still on the hunt for a fix – GrouchyPanda Jun 23 '16 at 23:11

0 Answers0