how to clear import cache of an file?

My project uses import to load submodules. And I want to make submodules reloadable without stopping the project: clearing the import cache of all mjs and ts files in the submodule folder and reimporting the entrypoint file. Is this possible to do in deno?
11 Replies
Doctor πŸ€–
Doctor πŸ€–β€’3w ago
I think the eval method or running these as a worker would be more appropriate. You can't unload an import module from my understanding, but you can make it think your attempt to load it again is a different module, but I wouldn't recommend doing that.
bartlomieju
bartlomiejuβ€’3w ago
That's correct, there's no way to "unload" a module that was imported
Doctor πŸ€–
Doctor πŸ€–β€’3w ago
I think that would go against the spec of the language
𝕀π•₯π•–π•§π•–πŸ˜πŸšπŸ˜πŸ πŸ™πŸπŸ˜πŸœ
For latecomers: you can clear the import cache in bun so that you can hot reload files easily. I'm currently trying to move my repo from deno to bun, but it's not going very well. bun's auto-install function is not as powerful as deno's nodemodulesdir=auto + --allow-scripts, this is an absolute fatal blow to my repo moving plan....
Doctor πŸ€–
Doctor πŸ€–β€’2w ago
What are you trying to do that requires sub modules to be reloadable?
𝕀π•₯π•–π•§π•–πŸ˜πŸšπŸ˜πŸ πŸ™πŸπŸ˜πŸœ
hard to describe. My repo allows users to upload char. After decompression or clone from url, main.mjs under the char folder will be loaded by the repo as an entry point to provide services to user. This is the reason why I hope bun’s auto-install can load all packages. I wish char authors can use the packages they want, but bun cannot do this for now. I wish that the reloading feature will make debugging easier for char authors, it would be useful if char could be easily reloaded without restarting the entire server. And I also want to deal with the situation where the user uninstalls the char and then installs a char with the same name but different content.
john smith
john smithβ€’2w ago
If possible, could you please teach me how to rewrite the deno project into a bun project? I don’t understand bun very well:lemon_deno:
𝕀π•₯π•–π•§π•–πŸ˜πŸšπŸ˜πŸ πŸ™πŸπŸ˜πŸœ
if you don't rely too much on deno's auto install and havent use deno's unique framework, move to bun is simple. you just need to replace all node: and npm: stuff to nothing and it's basically all. it's not difficult, just ask AI and try more!
john smith
john smithβ€’2w ago
oh, thank you! And good luck.