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
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.That's correct, there's no way to "unload" a module that was
import
edcan we add one in future?
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....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.
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!herere two commits for your reference
https://github.com/steve02081504/fount/commit/9be9e3e02f30ad741ce52dd04a364d8ff4235906
https://github.com/steve02081504/GentianAphrodite/commit/6db774e251b55133e8dc1a4e7fe0f881880ad228
bun's auto install cannot meet my repo, so Ill stay in deno for now. π
oh, thank you!
And good luck.