Delayed plugin initialisation
See original GitHub issueHey,
First of all, thanks for all the efforts on this, I like deno_mongo very much 😃
Now, here’s about the issue I’m encountering. I am trying to lazy-load deno_mongo for my project denodb which handles different types of databases. The problem being that if someone only wants to use mysql, the library shouldn’t load mongodb (which comes with additional command flags unstable and allow-plugin at least).
After digging in the code, I found a solution to lazy-load everything:
const { MongoClient, RELEASE_URL, init } = await import("../../unstable_deps.ts");
await init(RELEASE_URL);
const client = new MongoClient();
But obviously this is when I realised, this is already being done in mod.ts. The problem is, when lazy-loaded, the module doesn’t wait on the await init(...) instruction from that file.
Uncaught Error: The plugin must be initialized before use
So far, the only solution I found was to remove that line (with init) from my local package mod.ts. Otherwise, by keeping my additional await init(...), I am getting an error saying that I am trying to initialise the same plugin twice (which makes sense).
I am therefore asking: could something be done here so that this library could be lazy-loaded when necessary? I know this might only be my problem right now, but I am sure it might be someone else’s someday.
Just let me know if you could do something about this, any thought.
Thanks for your time and keep up the good work 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
The project was rewritten using TS. This will no longer be a issue
At the beginning, init was not included in mod.ts, until many people forgot to call init before using it, it exists in mod.ts.
One of the solutions is to use dynamic import to load the deno_mongo library in your integrated library