-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
Important feature: Allow busting ESM cache #38322
Comments
@nodejs/modules |
this is a duplicate but I can't find the other issue on my phone. tldr is either append some sort of unique id to the url each time you want to import it (foo.mjs?v=1) or bug v8 about getting proper hot reloading support. |
Would be great if we document |
As usual, here's a link to my article on implementing mocking modules, which use the above technique: https://dev.to/giltayar/mock-all-you-want-supporting-es-modules-in-the-testdouble-js-mocking-library-3gh1 |
This works, thank you @devsnek and @giltayar , we should really document this in the API docs: https://nodejs.org/api/esm.html#esm_no_require_cache . Closing this issue now |
This landed on node 22: Here is the person who found the "fix" The docs Here is where I first saw the merge |
Currently ESM modules are cached separately for ESM
imports
and dynamic imports. https://nodejs.org/dist/latest-v16.x/docs/api/esm.html#esm_no_require_cacheThere is currently no way to remove the ESM cache for specific files/modules in node.js/JavaScript context. I"m 100% sure about this unless there is some weird undocumented way. I even tried the following to bust the cache and it doesnt work:
This missing feature prevents writing ESM based javascript test runners because test files need to be re-evaluated without cache on file changes. In other words, cache busting for ESM modules is an important feature that node.js should provide somehow.
The text was updated successfully, but these errors were encountered: