Import-fresh bypasses the Node.js module cache to force a fresh import of a module, useful for testing and hot-reloading scenarios. Version 4.0.0 (latest stable, released 2025) requires Node.js ≥22.15 due to its use of ESM module loader hooks. Unlike older cache-clearing approaches (e.g., delete require.cache), import-fresh works with ESM and is the only maintained solution for Node's native ES module system. It uses a unique cache-busting URL per call, which grows memory over time (intended for development only). Sindre Sorhus maintains it with monthly releases.
npm install import-freshNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating an importFresh function and using it to bypass the module cache, showing state reset.
Use only in development or short-lived processes. Not suitable for production long-running servers.
Convert to ESM (type: module in package.json or .mjs extension).
Upgrade Node.js to >=22.15 or stay on v3 (which uses older Node.js APIs).
Pass import.meta.url; for CJS compatibility, use url.pathToFileURL(__filename).
Set skipNodeModules consistently; if you need different behaviors, run in separate processes.
import createImportFresh from 'import-fresh'
Use import instead of require; ensure your project is ESM (type: module) or use dynamic import().
Pass import.meta.url or new URL(import.meta.url).href
No dependency data recorded yet.