import-without-cache
v0.2.2
Published
Import ES modules without cache.
Readme
import-without-cache
Import ES modules without cache.
Features
- Import ES modules without cache
- All dependencies are also imported without cache
Install
npm i import-without-cacheUsage
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()
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 neededKnown Limitations
- Support Node.js since v22.15.0, and doesn't support Deno.
- For Bun,
clearRequireCacheworks, butinitis not needed since ESM imports is the same as CJS requires.
- For Bun,
- Only supports ESM modules by default. CommonJS cache can be cleared by
clearRequireCache. require(esm)is not supported.
Sponsors
License
MIT License © 2025-PRESENT Kevin Deng
