brython-dev / brython

Brython (Browser Python) is an implementation of Python 3 running in the browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inline scripts: "import declarations may only appear at top level of a module"

denis-migdal opened this issue · comments

I get the following error when importing :

Uncaught SyntaxError: import declarations may only appear at top level of a module

<!DOCTYPE html>
<html>
    <head>
        <title>BLISS example</title>
        <script src="../brython/www/src/brython.js" defer></script>
        <script src="../index.js" defer></script>
        <script type="text/python">
import javascript
javascript.import_js("../index.js", alias="BLISS")

class X( BLISS() ):
    def __init__(self):
        pass

BLISS.define("hello-world", X)
        </script>
    </head>
    <body>
        <hello-world></hello-world>
    </body>
</html>

Hum... it seems that contrary to what is stated in the documentation, javascript.import_js cannot be used to import JS modules...

I'll have to check more in depth how to do.

I'm closing the issue, I found a way to do it better.