{"id":46250,"library":"require-and-forget","title":"require-and-forget","description":"Require a Node module and immediately delete it from the module cache, forcing re-evaluation on the next require call. v1.0.1 is the latest stable version (no updates since 2017). Useful for testing scenarios where you need fresh module state (e.g., random values, mutable singletons). Key differentiator: lightweight and focused solely on cache eviction, unlike heavier testing utilities. Works with Node >=6, CommonJS only.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/bahmutov/require-and-forget","tags":["javascript","cache","load","loading","node","npm","purge","require","util"],"install":[{"cmd":"npm install require-and-forget","lang":"bash","label":"npm"},{"cmd":"yarn add require-and-forget","lang":"bash","label":"yarn"},{"cmd":"pnpm add require-and-forget","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS only; no ESM or named export. The module exports a single function.","wrong":"","symbol":"default (function)","correct":"const forget = require('require-and-forget')"}],"quickstart":{"code":"const forget = require('require-and-forget');\n// Assume random.js exists: module.exports = Math.random()\nconst r1 = forget('./random');\nconst r2 = forget('./random');\nconsole.log(r1 !== r2); // true - module not cached","lang":"javascript","description":"Demonstrates forcing re-evaluation of a module by removing it from cache after each require."},"warnings":[{"fix":"Use dynamic import() if you need ESM-like behavior, but caching behavior differs.","message":"Only works with CommonJS (require), not ES modules (import).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you want to keep the module cached, use regular require() instead.","message":"Module is removed from cache after require, so subsequent normal require() calls will re-evaluate it.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use paths as you would with require().","message":"Absolute or relative paths work; module resolution follows Node's algorithm.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2017':35 '6':67 'cach':16,58,71 'call':25 'commonj':68 'delet':11 'differenti':52 'e.g':46 'evalu':20 'evict':59 'focus':55 'forc':17 'forget':4 'fresh':43 'heavier':61 'immedi':10 'javascript':70 'key':51 'latest':29 'lightweight':53 'load':72,73 'modul':8,15,44 'mutabl':49 'need':42 'next':23 'node':7,66,74 'npm':75 'purg':76 'random':47 're':19 're-evalu':18 'requir':2,5,24,77 'require-and-forget':1 'scenario':39 'sinc':34 'singleton':50 'sole':56 'stabl':30 'state':45 'test':38,62 'unlik':60 'updat':33 'use':36 'util':63,78 'v1.0.1':26 'valu':48 'version':31 'work':64","created_at":"2026-06-07T12:59:00.515192+00:00","updated_at":"2026-06-07T12:59:00.515192+00:00","problems":[{"fix":"Ensure the path is relative to the calling file (not the module's directory) and the file exists.","cause":"Path passed to forget() is incorrect or file does not exist.","error":"Error: Cannot find module './random'"},{"fix":"Use const forget = require('require-and-forget');","cause":"Importing incorrectly (e.g., using destructured or ESM import).","error":"TypeError: forget is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/bahmutov/require-and-forget#readme","github":"https://github.com/bahmutov/require-and-forget","docs":null,"changelog":null,"pypi":null,"npm":"require-and-forget","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}