Esm: How to delete from cache?

Created on 19 Feb 2018  路  3Comments  路  Source: standard-things/esm

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?

question

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OmgImAlexis picture OmgImAlexis  路  3Comments

mbostock picture mbostock  路  3Comments

MVSICA-FICTA picture MVSICA-FICTA  路  3Comments

mAAdhaTTah picture mAAdhaTTah  路  3Comments

Mensu picture Mensu  路  3Comments