Exernal JavaScript file not working at first

Hello. This is a minor inconvenience, but I can’t figure out why Anki rejects any method from my external JS file AT FIRST on Desktop. What I mean :

  • in the editor, if I switch between the front and the back templates just once, it works just fine from there.
  • same when starting review : only the front of the very first card will show the error, but all the following cards with the same template work just fine. Even going back to the first card displays it properly.

The importing script is at the bottom of the editor and all script using methods from this file is written in another script tag lower.

Another bigger problem however is that JS doesn’t work at all on AnkiDroid with the imported file, but no error is shown, just the HTML.

Any idea of what’s happening ? Thank you in advance for your help.

The error :

Invalid HTML on card: ReferenceError: randomInt is not defined
ReferenceError: randomInt is not defined
at eval (eval at (http://127.0.0.1:54096/_anki/js/vendor/jquery.js:2:2651), :3:16)
at eval ()
at http://127.0.0.1:54096/_anki/js/vendor/jquery.js:2:2651
at Function.globalEval (http://127.0.0.1:54096/_anki/js/vendor/jquery.js:2:2662)
at Ha (http://127.0.0.1:54096/_anki/js/vendor/jquery.js:3:21262)
at n.fn.init.append (http://127.0.0.1:54096/_anki/js/vendor/jquery.js:3:22791)
at n.fn.init. (http://127.0.0.1:54096/_anki/js/vendor/jquery.js:3:24070)
at Y (http://127.0.0.1:54096/_anki/js/vendor/jquery.js:3:4515)
at n.fn.init.html (http://127.0.0.1:54096/_anki/js/vendor/jquery.js:3:23660)
at http://127.0.0.1:54096/_anki/js/reviewer.js:36:16