-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic Uncached Import (Feature Request) #14435
Comments
This is the last feature that prevents me from switching my app to bun. My backend manages and cordinates a lof of apis (each responsible for specific purposes). When I need to update an API, I don't have to reload the whole app. I just need to request the backend to reload (uncache) that specific API. I'm currently using "require.cache" to solve this problem.
|
I've also encountered this issue. I am watching files for update using fs.watch (https://bun.sh/guides/read-file/watch) Then I do "const { default: newFn } = await import(filePath)" Unfortunately, I've noticed newFn is always the same, which defeats the whole purpose of fs.watch in this case How did you solve it? @xd1gital |
To clear the import cache for a particular file, use |
Hey, This doesn't work With your approach you can delete only imports of first level which you know their specifier but wat if you do not know which imports are in the children imports, these will be still imported from cache |
What is the problem this feature would solve?
Imagine this setup:
file a.ts
file b.ts
file c.ts
Now when running this will console log the result of dynamic import, and THIS IS IMPORTANT the dynamic import has a query param which means Bun should import a fresh version each time
But if while this script runs you go to
c.ts
and change the string manually the console log will not change, since C inside B is cached which is supper bad since I have a query param in B and I expect a fresh version of it and it's child imports also should be not cached for this exact importWell that obsiously is kind of inconvenient, because that literally means you can't load user code since in runtime since it always will give the same result even if user manually changed this
Now I understand that this is not a bug, it is how ESM is designed to work and is the same in Node, Bun and Deno
And below is my proposal
What is the feature you are proposing to solve the problem?
What I'm proposing is a new API maybe called
uncachedImport
which will import that module/file and it's child imports in a uncached manier basically fresh versions each time the method is calledWhat alternatives have you considered?
There is
require.cache
which you can use to remove modules from cache, but it's not clear how to remove the child imports and I tried it I'm not even sure that it plays nicely with both import/require , and overall seems like a bad practice and couldn't make it working in Bun with both import/requireThe text was updated successfully, but these errors were encountered: