I have a use case where I need to remove a module from cache. With CJS you can do: delete require.cache[moduleName]. Is there a way of doing the same with ESM?
Hi @bensampaio!
Yes you can unlock CJS interop to expose ESM on Module._cache and require.cache.
{
"cjs": {
"cache": true
}
}
Thank you @jdalton! Will this be supported when Node releases ESM? I cannot find documentation for Module._each. Should I be using that instead of require.cache?
I typoed. I meant Module._cache.
Use whichever you have access to.
Node hasn't worked out how caches will be exposed yet.
Most helpful comment
I typoed. I meant
Module._cache.Use whichever you have access to.
Node hasn't worked out how caches will be exposed yet.