Registry / testing / require-without-cache

require-without-cache

JSON →
library0.0.6jsnpmunverified

A tiny utility to require Node.js modules while bypassing the module cache. Current stable version is 0.0.6 (released 2015, no updates since). It accepts a file path and the require function reference, then temporarily deletes the module from require.cache before loading, ensuring a fresh copy. Intended primarily for testing scenarios where stubbing or mocking modules requires uncached imports. Unlike other solutions that require explicit cache deletion, this wraps the require call to do it automatically.

npm install require-without-cache
INSTALL
IMPORT
SIG · REQUIRE-WITHOUT-CA
R
require-without-cache
testingjavascriptv0.0.6
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 requireWithoutCache from 'require-without-cache'
const requireWithoutCache = require('require-without-cache')
Package is ESM-compatible (type: module) from package.json? Actually package.json does not have 'type' field, so CJS require works. The package only exports default function.
requireWithoutCache
const requireWithoutCache = require('require-without-cache')
const { requireWithoutCache } = require('require-without-cache')
Package exports only the function as default, not as named export.
type (TypeScript)
import requireWithoutCache from 'require-without-cache'
import * as requireWithoutCache from 'require-without-cache'
No TypeScript types provided; package is JavaScript only.

Demonstrates basic usage: loading a module without cache by passing the path and the require function.

const requireWithoutCache = require('require-without-cache'); const freshModule = requireWithoutCache('./path/to/module', require);
Debug
Known issues
gotchaMust pass the correct 'require' reference from the calling module, otherwise cache manipulation may affect unintended modules.
fix
Always pass the local 'require' (the one in scope) to ensure correct cache operations.
affects: >=0.0.0
gotchaRequires the module to have 'require.resolve' and 'require.cache' on the passed require function. Custom require shims must provide these.
fix
If using a custom require, ensure it has 'resolve' and 'cache' properties as described in the documentation.
affects: >=0.0.0
gotchaPackage has not been updated since 2015. It may not work with newer Node.js versions (e.g., ESM-only modules, or changes to require.cache internals).
fix
For modern Node.js (>=14), consider using dynamic import() or other uncaching strategies.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Module "..." has already been loaded. Re-require can cause issues.
Using the function on a module that has already been required and cached normally; some modules resist reloading.
fix
Ensure the module is not imported elsewhere before calling requireWithoutCache, or use it before the first require.
TypeError: Cannot delete property 'cache' of undefined
Passed require function does not have a 'cache' property (e.g., browserify or bundler).
fix
Only use this package in Node.js environment where require.cache is available.
Upgrade
Version history
0.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
require-without-cache — npm install require-without-cache · libregistry