Page 1 of 1

Javascript port and undefined references

Posted: Fri Sep 10, 2021 5:20 am
by Devy
Hi,

I complied the latest MicroPython Javascript port (https://github.com/micropython/micropyt ... javascript) using the instructions on the port page but keep getting 'Uncaught ReferenceError: mp_js_init is not defined at'

I am using the exact HTML on that page with micropython.js and surrounding files in 'build' so that all files can be found as expected.

Is there something I am missing? I complied the port with the default instructions provided (make), using latest emsdk on 20.04 Ubuntu.

Re: Javascript port and undefined references

Posted: Tue Nov 09, 2021 2:05 pm
by TheMindVirus
I had the same issue, in 2021. After a bit of trial and error, I found the problem.

It is because even though window.load() or any global code should run after everything has been loaded or while it is loading,
Micropython bindings still haven't yet fully loaded by the time the browser reaches window.load().

A temporary solution is to use setTimeout() to trigger mp_js_init() 1000ms later and then it is defined and runs correctly.
A more acceptable solution is to use setInterval() to poll for if mp_js_init() has been defined yet or not when the browser is being slow.

Hope this helps. A.