[READ-ONLY] Mirror of https://github.com/sxzz/import-without-cache. Import ES modules without cache.
0

Configure Feed

Select the types of activity you want to include in your feed.

TypeScript 90.0%
JavaScript 10.0%
56 1 15

Clone this repository

https://git.vm.fail/sxzz.dev/import-without-cache https://git.vm.fail/did:plc:izygix4mav4kjuym5cnnsz5j
ssh://git@knot1.tangled.sh:2222/sxzz.dev/import-without-cache ssh://git@knot1.tangled.sh:2222/did:plc:izygix4mav4kjuym5cnnsz5j

For self-hosted knots, clone URLs may differ based on your setup.


README.md

import-without-cache#

npm version npm downloads Unit Test

Import ES modules without cache.

Features#

  • Import ES modules without cache
  • All dependencies are also imported without cache

Install#

npm i import-without-cache

Usage#

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

Known Limitations#

  • Supports Node.js v22.18.0 and later; Deno is not supported.
  • Yarn PnP is not supported on Node.js versions earlier than v24.
  • In Bun, clearRequireCache works, but init is unnecessary because ESM imports behave the same as CommonJS requires.
  • Only ESM modules are supported by default. The CommonJS cache can be cleared with clearRequireCache.
  • require(esm) is supported starting in Node.js v24.13.1.

Sponsors#

License#

MIT License © 2025-PRESENT Kevin Deng