Registry / devops / stealthy-require

stealthy-require

JSON →
library1.1.1jsnpmunverified

stealthy-require v1.1.1 is a Node.js library that bypasses the require cache to load fresh module instances. It works by clearing the cache, executing a callback where you require the module, then restoring the cache. Key differentiators: it handles nested dependencies (deep cache bypass), supports exceptions for specific submodules, and provides a workaround for Browserify. However, it cannot re-require native modules, and only bypasses the cache synchronously. The library is stable but sees infrequent updates (last release 2016-2017).

npm install stealthy-require
INSTALL
IMPORT
SIG · STEALTHY-REQUIRE
S
stealthy-require
devopsjavascriptv1.1.1
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.

stealthyRequire
const stealthyRequire = require('stealthy-require');
import stealthyRequire from 'stealthy-require';
This package is CommonJS-only and does not provide ESM exports. Use require().

Demonstrates basic usage and usage with exception callback to bypass the require cache for a module and its dependencies except specified ones.

const stealthyRequire = require('stealthy-require'); // Bypass require cache for 'request' and its dependencies const requestFresh = stealthyRequire(require.cache, function () { return require('request'); }); // With exception: keep 'tough-cookie' cached const requestFresh2 = stealthyRequire(require.cache, function () { return require('request'); }, function () { require('tough-cookie'); }, module); console.log(requestFresh === require('request')); // false console.log(requestFresh2 === require('request')); // false
Debug
Known issues
gotchaCannot bypass cache for native modules (e.g., fs, http). Only works for JavaScript modules.
fix
Only use stealthy-require for non-native modules. Native modules cannot be required twice.
affects: >=0.0.0
gotcharequire cache is only bypassed for synchronous operations during module loading. Lazy-loaded modules later will use cached versions.
fix
Ensure that the module you bypass does not lazy-load other modules after initial require.
affects: >=0.0.0
gotchaRepeatedly calling stealthy-require without care can cause memory leaks because module.children retains references to old instances.
fix
Manually clean up module.children or use a module reinitialization pattern that avoids accumulating references.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'stealthy-require'
Package not installed or wrong import path.
fix
Run 'npm install stealthy-require' and ensure require('stealthy-require') is used.
stealthyRequire is not a function
Using default import syntax with an ESM bundler that doesn't handle CJS interop correctly.
fix
Use const stealthyRequire = require('stealthy-require').default or require('stealthy-require') as shown in docs.
TypeError: Cannot read property 'cache' of undefined
Passing a non-object as first argument (e.g., undefined in browserify context).
fix
In Browserify, pass arguments[5] instead of require.cache.
stealthyRequire(...) is not restoring the cache correctly
Throwing an error inside the callback may leave cache uncleared.
fix
Wrap your callback to handle errors and ensure cache restoration, or use a try-finally block.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Amazon
1
Resources
stealthy-require — npm install stealthy-require · libregistry