Clear a module from the Node.js require cache, forcing a fresh reload on the next require. Current stable version is 4.1.3 (last updated 2020, Node >=8). It recursively clears the target module and all its parent modules from the cache. Alternatives like delete require.cache[require.resolve(...)] do not handle recursive clearing. Common use case: testing where modules have state or need to be reloaded. Ships TypeScript definitions. Low maintenance, no dependencies.
npm install clear-moduleNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates using clear-module to reset a module's cached exports. Shows ESM import, creating a require, and verifying fresh state.
Use import or upgrade to Node >=12.22.0 with --experimental-modules flag if needed, or downgrade to v3.
Upgrade Node.js to v8 or higher.
Use clearModule.all() only when needed; prefer targeted clears.
For ESM cache clearing, use dynamic import with cache busting (e.g., import(`${url}?update=${Date.now()}`)).Use dynamic import: const clearModule = (await import('clear-module')).default;Run `npm install clear-module` in your project root.
Use `import clearModule from 'clear-module'` (default import) not `import * as clearModule from 'clear-module'`.
Ensure moduleId is the same string you pass to require(), including relative path (e.g., './foo').
No dependency data recorded yet.