Registry / testing / decache

decache

JSON →
library4.6.2jsnpmunverified

decache is a lightweight utility (v4.6.2, stable, low maintenance) that deletes a module from Node.js require.cache, enabling fresh require() calls for testing or hot-reloading. It works with .js, .json, and other extensions, but ignores native .node modules. Unlike alternatives that require hacking require.cache directly, decache handles edge cases (e.g., parent module references) and includes TypeScript definitions. Released under MIT, with a small footprint and no dependencies.

npm install decache
INSTALL
IMPORT
SIG · DECACHE
D
decache
testingjavascriptv4.6.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.

default
import decache from 'decache'
const decache = require('decache')
ESM default import; named import not available. CommonJS require still works.
decache (type)
import decache from 'decache'
import { decache } from 'decache'
This is a default-export package; named import will fail.
require('decache') (CommonJS)
const decache = require('decache')
const { decache } = require('decache')
CommonJS default export, not named.

Demonstrates decaching a module and re-requiring it to get a fresh copy.

import decache from 'decache'; // Assuming a module 'myModule.js' exists let mod = require('./myModule.js'); console.log(mod.someValue); // initial state decache('./myModule.js'); mod = require('./myModule.js'); // fresh module console.log(mod.someValue); // initial state again
Debug
Known issues
gotchaNative .node modules are ignored by decache and will not be removed from cache.
fix
Do not rely on decache for native modules; unload them manually if needed.
affects: >=1.0.0
gotchadecache removes all cached instances of a module, including those from parent modules, which may cause unexpected behavior if other modules hold references.
fix
Ensure no other module depends on the cached instance you are deleting.
affects: >=1.0.0
breakingIn v4, the module switched to ESM-first with TypeScript types. CommonJS require still works via default export.
fix
Use import decache from 'decache' in ESM or const decache = require('decache') in CJS.
affects: >=4.0.0
Errors
Common errors & fixes
Cannot find module 'decache'
decache not installed or not in node_modules.
fix
Run: npm install decache --save-dev
TypeError: decache is not a function
Incorrect import: using named import instead of default.
fix
Use: import decache from 'decache' or const decache = require('decache')
Error: Module './mymodule.js' has already been required and cached
Attempting to decache a module that hasn't been required yet.
fix
Require the module first, then decache it.
Upgrade
Version history
4.6.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
decache — npm install decache · libregistry