• As you may know, I'm currently developing an "Analog Clock Construction Kit" which (currently) heavily relies on external modules required from GitHub.

    However, there are modules which behave differently depending on whether they are actually loaded from GitHub (by the Web IDE) or manually inserted into the code using the following "trick"

    let exports = {}
      <<<< insert module here
    let XXX = exports
    

    as a replacement for

    let XXX = require('<GitHub URL>');
    

    Two modules are affected - and I don't know why:

    • rounded clock hands - work fine when inserted manually, but produce wrong graphics when loaded from GitHub
    • smart clock size calculator - works fine (even if loaded from GitHub), but produces an annoying error toast (Error: Unreachable point. logically broken. in https://raw.githubusercontent.com/rozek/­banglejs-2-smart-clock-size/main/ClockSi­ze.js) in the WebIDE

    Does anybody have any ideas how to solve these problems?

  • My guess is the IDE is set to automatically minify modules, so when you include via the IDE they get minified.

    Espruino doesn't handle let with scoping, so it's possible if you have used let in your code a lot the minifier has decided to name two variables a in the same function, and that's causing some issues? Maybe if you disable module minification in the IDE settings it'll work which will at least prove the problem?

  • Yes, that's it!

    Both problems disappear as soon as I disable module minification.

    May I solve this problem by using var instead of let?

  • I got "rounded clock hands" working by replacing let with var - with minification switched on!

    However, the "smart clock size calculator" still produces that annoying toast...

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

strange behaviour of some modules when required from GitHub

Posted by Avatar for Andreas_Rozek @Andreas_Rozek

Actions