Error: Module name "sharemaps_drawonmaps_elgg_js" has not been loaded yet for context: _

Hi!

I'm trying to use the Sharemaps plugin to create and edit the user maps. Cannot to resolve the issue..

Error: Module name "sharemaps_drawonmaps_elgg_js" has not been loaded yet for context: _ https://requirejs.org/docs/errors.html#notloaded

This is looks strange for me but looks like plugin depends froms the self?

 

drawonmaps_elgg.js

define(function (require) {
    var elgg = require('elgg');
    var $ = require('jquery');
    
    require('sharemaps_googleapis_js');
    require('sharemaps_prettify_js');
    require('sharemaps_drawonmaps_elgg_js'); -- This is the error place

 

 views.php

<?php
/**
 * Elgg ShareMaps plugin
 * @package sharemaps
 */
 
return [
    'default' => [
    'sharemaps_drawonmaps_elgg_js.js' => __DIR__ . '/vendors/drawonmaps/drawonmaps_elgg.js',
    'sharemaps_gmaps_js.js' => __DIR__ . '/vendors/drawonmaps/gmaps.js',
    'sharemaps_prettify_js.js' => __DIR__ . '/vendors/drawonmaps/prettify.js',
    'sharemapsps_api/graphics/' => __DIR__ . '/graphics',
    ],
];

Possibly the issue exist from timeout or form loop in the required info?

Please any ideas?

 

  • Did you shim your JS by setting exports and deps in elgg_define_js in init{} of your start.php ?

  • Hi RvR!

    Yes, this is in the start.php of a module

    elgg_define_js('sharemaps_drawonmaps_elgg', array(
            'deps' => array('jquery','sharemaps_drawonmaps_elgg_js'),
            'exports' => 'sharemaps_drawonmaps_elgg',
        ));
  • Try this:

    // views
    return [
        'default' => [
            'drawonmaps_elgg' => __DIR__ . '/vendors/drawonmaps/drawonmaps_elgg.js',
              ....
        ],
    ];
    
    // start
    elgg_define_js('drawonmaps_elgg', [
        'deps' => ['jquery']
    ]);
    
    // js
    define(function (require) {
        var elgg = require('elgg');
        var $ = require('jquery');
        require('drawonmaps_elgg'); ....

     

  • And another trick is:

    // views
    return [
        'default' => [
            'drawonmaps/drawonmaps_elgg' => __DIR__ . '/vendors/drawonmaps/drawonmaps_elgg.js',
            ...
        ],
    ];
    
    // start
    elgg_define_js('drawonmaps/drawonmaps_elgg', [
        'deps' => ['jquery']
    ]);
    
    // js
    define(function (require) {
        var elgg = require('elgg');
        var $ = require('jquery');
        require('drawonmaps/drawonmaps_elgg');
        ...
  • Hi RvR!

    Thank you!

    Tried both solutions, but unfortunately without results the first one lead to the same Loading timeout but the second one shows:

    Loading <script> at http: // localhost: 8080 / cache / 1546180544 / default / sharemaps_drawonmaps_elgg_js.js failed. 

    the views.php:

        'drawonmaps/sharemaps_drawonmaps_elgg_js.js' => __DIR__ . '/vendors/drawonmaps/drawonmaps_elgg_js.js 

     start.php

        elgg_define_js('drawonmaps/sharemaps_drawonmaps_elgg_js', [
        'deps' => ['jquery']
    ]);  

    drawonmaps_elgg_js.js there is also drawonmaps_elgg.js

    define(function (require) {
        var elgg = require('elgg');
        var $ = require('jquery');
        
        require('sharemaps_googleapis_js');
        require('sharemaps_prettify_js');
        require('drawonmaps/sharemaps_drawonmaps_elgg_js');

     

     But the error is:

    Loading <script> at http: // localhost: 8080 / cache / 1546180544 / default / sharemaps_drawonmaps_elgg_js.js failed.

  • In above reply:

    'drawonmaps/sharemaps_drawonmaps_elgg_js.js' => __DIR__ . '/vendors/drawonmaps/drawonmaps_elgg_js.js

    use:

    'drawonmaps/sharemaps_drawonmaps_elgg_js' => __DIR__ . '/vendors/drawonmaps/sharemaps_drawonmaps_elgg_js.js 

    Or change name of your JS on shortname aka drawonmaps.js.

    In views don't use .js at the end of your defined JS:

    script => script.js

    In start.php use only defined JS, eg:

    elgg_define_js('script', [
        'deps' => ['jquery']
    ]);

    Then require it:

    require('script');

    Use browser's console for checking errors.

    Run 'Flush the caches' always after changings

  • RvR, thank you very much for your help !

    Yes I've Flush the caches in the admin site console.

    After trying to implement short names without JS at the defined JS - received many not found errors. These changes are very huge as they are related to many files. I suppose the long name to defined was used as naming convention of the plugin author. Also in the docs for view's I founded that .js exist in the definition http://learn.elgg.org/en/stable/guides/javascript.html#setting-the-url-of-a-module 

    So I've reinstalled the plugin from the git. Possibly the first error is easy to resolve. 

    The error looks like this:

    uncaught exception: Google Maps API is required. Please register the following JavaScript library http://maps.google.com/maps/api/js?sensor=true.
     

    ReferenceError: GMaps is not defined[Подробнее] drawonmaps.js:54:9

     in the views/default/sharemaps/drawmon.js there are:

    define(function (require) {
        var elgg = require('elgg');
        var $ = require('jquery');
        require("sharemaps_googleapis_js");
        require("sharemaps_gmaps_js");
        require('sharemaps_prettify_js');
        require('sharemaps_drawonmaps_elgg_js');

     

    in the vendors/drawonmaps/drawonmaps_elgg.js there are

    define(function (require) {
        var elgg = require('elgg');
        var $ = require('jquery');
    
    

    and in the start.php 

     // register extra js files
        $mapkey = trim(elgg_get_plugin_setting('google_api_key', SHAREMAPS_PLUGIN_ID));
        elgg_define_js('sharemaps_googleapis_js', array(
            'src' => "//maps.googleapis.com/maps/api/js?key={$mapkey}&quot;,
            'exports' => 'sharemaps_googleapis_js',
        ));


        elgg_define_js('sharemaps_gmaps_js', array(
            'exports' => 'sharemaps_gmaps_js',
        ));

     

    The maps was showed once after loading but after refresh we have an error above.

    Possible I should open the new ticket for this. Sorry.. 

     

  • in the docs for view's I founded that .js exist in the definition

    That's right. I've suggested some of solutions only.

    Recommend ask / open issue on Sharemap's repo also.

    BTW, you can find more plugins related with GMaps API there ;)

  • in the vendors/drawonmaps/drawonmaps_elgg.js there are

    Use /vendors directory for 3-rd party JS libs only.

    If your drawonmaps_elgg.js is defined (used RequireJS) already then move it on:

    /mod/your-cool-plugin/view/default/js/drawonmaps/drawonmaps_elgg.js

    Then use elgg_require_js(); on the view/page which you need this JS.

    In your case is:

    elgg_require_js('drawonmaps/drawonmaps_elgg');  // calls /mod/your-cool-plugin/view/default/js/drawonmaps/drawonmaps_elgg.js
  • Good example for using JS libs which requires API's keys is reCaptcha

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking