For text entry, I would recommend looking at the demo experiments in this post: Transcription task online
The main thing is that import doesn’t work the same way in JavaScript, and you don’t have access to the same libraries that you do in Python. It looks like you’re trying to define a module or add something to a module in your code here, but I would avoid that if at all possible. If you need to define a custom function, just define the function itself, but I suspect with the code from the demo task you can do this in a much simpler way.