Search code examples
javascriptjquerynode.jsrequire

Uncaught Error: Script error for: jquery(…)


I'm trying to load a plugin that needs jquery to work jquery.countdown

I was getting this error when calling the plugin on my init class:

GET http://localhost:3008/js/jquery.js 404 (Not Found)

require.js:166 Uncaught Error: Script error for: jquery(…)

This was my starting code:

    define(function (require) {
    var commons = require('commons'), 
    core = require('core/core_library'),
    $ = require('vendor/jquery'),
    ButtonStatus = require('module-pf/ButtonStatus'),
    Archive = require('module-pf/Archive'),
    Countdown = require('appvendor/jquerycountdown');

    });

So I started investigating. First, the jquery.countdown library os correctly loaded , as debug says:

Countdown correctly loaded

So I guessed require doesn't know the loading order of those libraries. After some research, I saw that you can just nest dependencies to order them:

  define(['commons'], function () {
  require(['vendor/jquery'], function (commons) {

    //Added this for testing by calling jquerycountdown internal funcionality

    require(['appvendor/jquerycountdown'], function (inyectedCountdown) {
      $('#timer').countdown('2020/10/10', function (event) {
        $(this).html(event.strftime('%D days %H:%M:%S'));
      });
    });
  });
});

But I still get the same error. I have no idea what is happening, maybe incompatible jquery versions? I added that library manually. Jquery is working fine in my project but it is loading two instances, one located in js/jquery (404) and the second one in vendor/js/jquery (200).


Solution

  • This is how I solved it:

    Inside jquerycountdownlibrary we found a define calling jquery:

        define([ "jquery" ], factory);
    

    So I just added vendor/jquery.