Registry / testing / wipe-node-cache

wipe-node-cache

JSON →
library2.1.2jsnpmunverified

A utility to clear Node.js's require cache in a controlled, selective way. Version 2.1.2 is stable with no recent updates. Unlike blanket cache clearing, it uses filter and bubble callbacks to selectively wipe specific modules and their dependents. Useful for testing to reload modules freshly without restarting the process.

npm install wipe-node-cache
INSTALL
IMPORT
SIG · WIPE-NODE-CACHE
W
wipe-node-cache
testingjavascriptv2.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

wipe (default)
import wipe from 'wipe-node-cache'
const { wipe } = require('wipe-node-cache')
CommonJS users should use const wipe = require('wipe-node-cache'); ESM users default import.
wipe (CommonJS)
const wipe = require('wipe-node-cache')
const { default: wipe } = require('wipe-node-cache')
The package exports a single function; destructuring or accessing .default is incorrect.
TypeScript usage
import wipe from 'wipe-node-cache'
import * as wipe from 'wipe-node-cache'
No type definitions shipped; use @ts-ignore or declare module.

Selectively wipes module './foo.js' from require cache, then re-requires it to get fresh instance.

import wipe from 'wipe-node-cache'; // foo.js: let i = 0; module.exports = () => ++i; const foo1 = require('./foo.js'); console.log(foo1()); // 1 const foo2 = require('./foo.js'); console.log(foo2()); // 2 (still cached) wipe(null, (moduleName) => moduleName.includes('foo.js')); const foo3 = require('./foo.js'); console.log(foo3()); // 1 (fresh)
Debug
Known issues
gotchaThe first argument to wipe() is a stubs object. Passing null as first argument is correct, but passing an object with properties that shadow module names can cause confusion.
fix
Ensure first argument is an object of stubs or null; do not mix filter and stub logic.
affects: >=1.0.0
gotchaThe filterCallback receives (stubs, fileName, module). The module argument may be undefined, causing path.dirname(undefined) errors if accessed without check.
fix
Always guard against undefined module: if (module) { /* use module */ }
affects: >=1.0.0
gotchaBubble callback is called on every dependent module; returning false does not prevent the parent from being wiped if the child is wiped. The bubble callback only decides whether to wipe the dependent.
fix
Return true in bubbleCallback for modules you want to wipe; false to keep them.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: path.dirname is not a function
The module argument inside filterCallback is sometimes undefined, and code assumes it's a string to pass to path.dirname.
fix
Check if module is defined before calling path.dirname(module).
Cannot find module './foo.js' after wipe
Wiping a module that is from node_modules or core may cause subsequent require to fail if the module is not in module.paths.
fix
Avoid wiping core modules or modules not in the regular load path; use filter to exclude node_modules.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
Resources
wipe-node-cache — npm install wipe-node-cache · libregistry