Registry / testing / requirefresh

requirefresh

JSON →
library5.13.0jsnpmunverified

Node.js utility to load modules without caching them in require.cache. Current version 5.13.0, maintained by Bevry. Provides synchronous (requireFresh), callback (requireFreshCallback), and promise (requireFreshPromise) APIs. Ships TypeScript types. Useful for reloading config files or hot-reloading modules during development. Alternatives like decache exist but requirefresh offers a simpler API with multiple call patterns.

npm install requirefresh
INSTALL
IMPORT
SIG · REQUIREFRESH
R
requirefresh
testingjavascriptv5.13.0
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.

requireFresh
import { requireFresh } from 'requirefresh'
const requireFresh = require('requirefresh')
ESM import since v5; CommonJS require gives the module object, not the function. Use named import.
requireFreshCallback
import { requireFreshCallback } from 'requirefresh'
const requireFreshCallback = require('requirefresh').requireFreshCallback
Same as above; named export available in ESM.
requireFreshPromise
import { requireFreshPromise } from 'requirefresh'
const requireFreshPromise = require('requirefresh').requireFreshPromise
Promise-based API available via named export.

Demonstrates synchronous, callback-based, and promise-based loading of a JSON file without Node's require cache.

import { requireFresh, requireFreshCallback, requireFreshPromise } from 'requirefresh'; // Synchronous usage try { const pkg = requireFresh('./package.json'); console.log('Loaded without cache:', pkg.name); } catch (error) { console.error('Failed to load:', error); } // Callback pattern requireFreshCallback('./package.json', (error, result) => { if (error) console.error(error); else console.log('Callback result:', result.name); }); // Promise pattern requireFreshPromise('./package.json') .then(result => console.log('Promise result:', result.name)) .catch(error => console.error(error));
Debug
Known issues
breakingVersion 5.x changed module system from CJS to ESM. CommonJS require() now returns an object with named exports.
fix
Use import { requireFresh } from 'requirefresh' instead of const requireFresh = require('requirefresh').
affects: >=5.0.0
deprecatedrequireFreshCallback is deprecated and will be removed in a future major version.
fix
Use requireFreshPromise or requireFresh instead.
affects: >=5.0.0
gotchaThe module only works with Node.js CommonJS modules. It cannot bypass the cache for ES modules or .mjs files.
fix
Use dynamic import() for ES modules.
affects: *
gotchaRelative paths are resolved from the caller's location, not the module's location.
fix
Always use absolute paths or paths relative to __dirname/import.meta.url.
affects: *
gotchaIf the file is not found or has syntax errors, an error is thrown; ensure proper error handling.
fix
Wrap synchronous calls in try/catch or use promise/callback APIs.
affects: *
Errors
Common errors & fixes
TypeError: requireFresh is not a function
Using CommonJS require() on package version >=5 which uses ESM imports.
fix
Use import { requireFresh } from 'requirefresh' or switch to CommonJS require: const { requireFresh } = require('requirefresh')
Cannot find module './package.json'
Relative paths are resolved from the calling module's location, not current working directory.
fix
Use path.resolve(__dirname, './package.json') or path.join(process.cwd(), 'package.json')
requireFresh is not a function (but it's called as a function)
Attempting to call the default export instead of named export on ESM version.
fix
Import as import { requireFresh } from 'requirefresh'; do not import default.
requireFreshPromise is not a function
Typo or using wrong import method; ensure correct named import.
fix
Import as import { requireFreshPromise } from 'requirefresh';
Upgrade
Version history
5.13.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
requirefresh — npm install requirefresh · libregistry