$ npm install import-without-cache
Import ES modules without cache.
npm i import-without-cache
import { clearRequireCache, init, isSupported } from 'import-without-cache'
if (!isSupported) {
throw new Error('import-without-cache is not supported in this environment.')
}
const deregister = init({
// Optional
skipNodeModules: false,
})
const mod = await import('some-module', { with: { cache: 'no' } })
clearRequireCache() // Optional: clear CommonJS cache if needed
// or
const mod2 = await import(`no-cache://some-module`)
expect(mod).not.toBe(mod2) // Different instances
deregister() // Optional: deregister the hooks when no longer needed
clearRequireCache works, but init is unnecessary because ESM imports behave the same as CommonJS requires.clearRequireCache.require(esm) is supported starting in Node.js v24.13.1.MIT License © 2025-PRESENT Kevin Deng
© 2010 - cnpmjs.org x YWFE | Home | YWFE