Registry / devops / delete-node-require-cache

delete-node-require-cache

JSON →
library1.9.0jsnpmunverified

A Node.js library (v1.9.0, stable) to clear the require cache for a specified JS file, including parsing and removing cache for its internal dependencies. Useful for hot-reloading or testing scenarios where cached modules must be invalidated. Ships TypeScript types. Minimal overhead with no runtime dependencies. Activates on first call, with subsequent calls being no-ops.

devops
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.

The package exports a named function, not a default export.

import { delRequireCache } from 'delete-node-require-cache'

CommonJS requires destructuring because the export is a named object.

const { delRequireCache } = require('delete-node-require-cache')

Type import for TypeScript projects when only using the type (e.g., typeof).

import type { delRequireCache } from 'delete-node-require-cache'

Demonstrates importing and using delRequireCache to clear the require cache for a specific file.

import { delRequireCache } from 'delete-node-require-cache'; // Path to a JS file that has been required before const filePath = '/path/to/myModule.js'; delRequireCache(filePath); console.log('Cache cleared for', filePath);
Debug
Known footguns
gotchaThe function only clears cache for a single file and its direct dependencies. Nested dependencies of those dependencies are not recursively cleared.
gotchaCalling delRequireCache on a file that has never been required will throw an error because the module is not in cache.
gotchaThe library is ESM-only, but can still be used in CommonJS via dynamic import().
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
10 hits · last 30 days
gptbot
3
bingbot
1
ahrefsbot
1
Resources