Sporadic Javascript Loading Errors

Sporadic Javascript Loading Errors

написао/ла Alex M -
Број одговора: 5

We have the problem that on some cases, dynamic autocomplete fields are not working.

For example, we are on /enrol/instances.php?id=13 and press the edit button.

In like 50% of the cases, the edit page does not load properly on our stage server.

The problem mostly appears on firefox 82

Locally we cannot reproduce it.

$CFG->cachejs is not set. If we set it to false, we get other JS errors.

We found this bug report: 

https://tracker.moodle.org/browse/MDL-67327

But on our Moodle version this should be already fixed. We are on ('3.8.1 (Build: 20200113)


Uncaught TypeError: a is not a function

    <anonymous> https://example.com/lib/requirejs.php/1603719734/core/first.js:52

    execCb https://example.com/lib/javascript.php/1603719734/lib/requirejs/require.min.js:5

    check https://example.com/lib/javascript.php/1603719734/lib/requirejs/require.min.js:5

    enable https://example.com/lib/javascript.php/1603719734/lib/requirejs/require.min.js:5

    bind https://example.com/lib/javascript.php/1603719734/lib/requirejs/require.min.js:5

    emit https://example.com/lib/javascript.php/1603719734/lib/requirejs/require.min.js:5

    each https://example.com/lib/javascript.php/1603719734/lib/requirejs/require.min.js:5

    emit https://example.com/lib/javascript.php/1603719734/lib/requirejs/require.min.js:5

    check https://example.com/lib/javascript.php/1603719734/lib/requirejs/require.min.js:5

    

The code at this position is


define('core/first', [

'jquery'

], function (a) {

a(document).bind('ajaxStart', function () {

M.util.js_pending('jq')

}).bind('ajaxStop', function () {

M.util.js_complete('jq')

})


and should normally work to my understanding.


How can this be debugged and fixed?


Просек оцена:Useful (1)
У одговору на Alex M

Re: Sporadic Javascript Loading Errors

написао/ла Alex M -
I am also sometimes getting

"Uncaught Error: Mismatched anonymous define() module"
У одговору на Alex M

Re: Sporadic Javascript Loading Errors

написао/ла Alex M -
The code in my HTML file looks like this


M.util.js_pending("core/first");require(['core/first'], function() {
;

require(
[
'jquery',
'block_recentlyaccessedcourses/main'
],
function(
$,
Main
) {
var root = $('#block-recentlyaccessedcourses-5f9bd9c305eb45f9bd9c304c5c2');
var userid = root.attr('data-userid');

Main.init(userid, root);
});



https://requirejs.org/docs/errors.html#mismatch states

> If you manually code an HTML script tag, be sure it only includes named modules, and that an anonymous module that will have the same name as one of the modules in that file is not loaded.

I think this applies here ... and isn't require() always a anonymous module? Is that the problem?
У одговору на Alex M

Re: Sporadic Javascript Loading Errors

написао/ла Alex M -
So we are trying to identify anonymous modules....

Searching in PHPStorm for RegExp

"define\([:space:]*function"

leads to several modules.

Are all these modules wrong?


But this is even happening in the core:

public/lib/amd/src/backoff_timer.js:26

define(function() {



EDIT: in public/lib/amd/build/backoff_timer.min.js there is module name, so that does not seem to be the problem.


Question: How can I identify the anonymous defines? And is that also the problem for the first error?
У одговору на Alex M

Re: Sporadic Javascript Loading Errors

написао/ла Alex M -