#2684·brython

javascript.import_js() crashes but javascript.import_modules() works fine

Author: cjlee112Created May 14, 2026Updated May 14, 2026

Running javascript.import_js('https://threejs.org/build/three.module.js', alias='THREE') crashes with javascript error message "Uncaught SyntaxError: Cannot use import statement outside a module". Note this is just the module used in the Gallery example (https://brython.info/gallery/three_webgl_interactive_cubes.html).

But running the exact same thing with import_modules() works fine:

def run_three(THREE):
    geometry = THREE.BoxGeometry.new(20, 20, 20)
    print('run_three OK')

javascript.import_modules(['https://threejs.org/build/three.module.js'], run_three)

Crash occurs on both 3.13 and 3.14, tested on Chromium 147