Search code examples
javascriptdojobuild-system

Dojo Build System - using async plugin with google maps api


I'm trying to build a dojo app and am encountering one error that I can't seem to fix.

The app runs without error unbuilt and I am trying to use the Dojo Build System to optimize the files into one layer.

The error is related to the following import:

define([
  'plugins/async!//maps.google.com/maps/api/js?v=3'
  //...

The error is

error(308) Failed to evaluate AMD define function.
module: gis/dijit/StreetView; text: 

'gis/plugins/async!
error: SyntaxError: Unexpected token ILLEGAL
error(352) Optimizer reported errors; consult build report for details.

The async plugin looks something like this:

define(function () {

var cb = '_asyncApiLoaderCallback';
return {
    load: function (param, req, loadCallback) {
        if (!cb) {
            return;
        } else {
            window.dojoConfig[cb] = function () {
                delete window.dojoConfig[cb];
                cb = null;
                loadCallback();
            };
            require([param + '&callback=dojoConfig.' + cb]);
        }
    }
};
});

Solution

  • The solution to this problem was to switch to the google maps loader from bower/npm.

    https://github.com/Carrooi/Js-GoogleMapsLoader

    The dojo build system appears to treat the // in the path like a comment, which makes paths like

    'my/plugin!http://www.google.com'
    

    show up as

    'my/plugin!http:
    

    This causes an error because everything after the // is a comment now and there's no apostrophe.. In addition the path www.google.com is obviously missing.