Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
How to invalidate ES module cache #1399
ES modules docs state:
Where's that separate cache? I need to invalidate it as it can be done in CommonJS modules for testing purposes.
How can I access that cache? Or, how can I completely invalidate the module cache?
Thank you in advance!
Oops! And does changing the
In fact, I've implemented ES module mocking already but it fails to work in some scenarios because of caching:
Also, does this WIP hooks are available in nightly builds? I really need an approach to mock modules or I'll need to face a very disturbing refactor in my project codebase.
@mfidemraizer es modules are still in development so i wouldn't recommend migrating your project over to them just yet. Mocking/development are high on our list of things to support so don't worry about not having that ability in the future.
Yeah that's fine. We use the full URL internally (including query and hash) for the cache key.
@devsnek Nice (about both hooks with mocking and the thing of URLs).
My concern with randomizing URLs is I'm not breaking an entire dependency tree if I'm not mistaken: say there's a module A which mocks some import: I need to randomize URLs for all modules having the mocked module dependency too. Right?
Probably I am misunderstanding something but I cannot confirm this to be true.
// esm.mjs console.log('Hello, ESModules!');
// import-esm.mjs import './esm?query=1'; import './esm?query=2';
$ node --experimental-modules import-esm (node:40370) ExperimentalWarning: The ESM module loader is experimental. Hello, ESModules!