Resolved: Drawing .svg with javascript module “RDKIT-JS”

Question:

first of all I’m relatively new to javascript. So I’m sorry if my question is dumb. I would like to draw a molecule on my webiste by using this tool https://github.com/rdkit/rdkit-js. I also found an example here https://iwatobipen.wordpress.com/2021/12/29/create-desktop-chemoinformatics-application-with-js-chemoinformatics-rdkit-js/comment-page-1/. This example works in my case but when i try to invoke a function to draw a molecule as a .svg without using the example code, I fail. I get this error-message in my browser:
In the following code example you can see the first case where it works and the second case were it doesn’t. In both cases i use the same function.:
Later i would like to use the module to dynamically make those images. I use django as the framework. In this case i tried to present a minimal example without the django stuff.
Thanks in advance for your effort!

Answer:

You are calling drawmol() before RDKit is ready.
To fix this, place it after RDKit is loaded:

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com