sindresorhus

clear-module

Clear a module from the cache

by sindresorhus

JavaScript

JavaScript98.6%
TypeScript1.4%

Commit activity

Last 12 weeks · 0 commits

Full graph →

Community health

4 of 6 standards met

Community profile →
71
✓README✓License✓Contributing✓Code of Conduct○Issue Template○PR Template

Recent PRs & issues

Quiet · 3 discussions · Last activity 5mo ago
See all on GitHub →
MCArth

Due to v8 stack traces only going so many deep by default, modules deep enough in the dependency tree such that clear has been called >~8 times do not get cleared. This is because resolve/parentModule relies on the v8 stack trace. It seems to me we don't need to resolve moduleId when calling it recursively from within clear, since children are absolute paths. I've copied this module into our project and fixed as so:

MCArth · 2y ago
sindresorhus
Support ESMOpenIssue

We need to wait for the loader hooks to be stable first: https://nodejs.org/dist/latest/docs/api/esm.html#esm_hooks

sindresorhus · 3y ago
sindresorhus

See the previous attempt and the feedback given there: https://github.com/sindresorhus/clear-module/pull/15 If you decide to work on this, you should have a lot of JS experience and be willing to do a good effort.

sindresorhus · 5y ago
Fadoli

Hey we've been using this module a bit, and I've encountered an issue with it. It seems you don't filter out native module, and as per nodejs documentation this causes bad behavior when re-requiring code later on. This documentation as been added there : https://github.com/nodejs/node/commit/5c14d695d2c1f924cf06af6ae896027569993a5c To reproduce, clear-module and reimport any library that internally uses a native library ( '.node' file ) I'm getting an when requiring it back and more specifically when the codes tries to call a function (that's within the .node )

Fadoli · 5mo ago
Jah-yee

Summary Fixes #18 — clear-module doesn't skip native modules. Problem clear-module currently removes native modules ( files) from . Re-requiring these after deletion causes , per the Node.js documentation linked in #18. Solution Skip files early in — just return without attempting to delete them from the cache. This matches the documented Node.js behavior. Testing Existing tests pass. This change is purely additive — it only adds an early return for native modules, no behavior change for JS modules.

Jah-yee · 5mo ago
sondregj

When clearing a module, certain child modules seem to be skipped. This seems to be because the array is mutated with an -call inside the next recursive call to , skipping certain indices in the outer -loop over children. Making a new array fixes the issue. Looking at the test , before using , is executed. I am not sure if this is part of the expected usage of the function, but the test fails if it is removed. If you swap the order of the imports in , the test succeeds. I chose to split the commits into three so that you may first review the failing test, and then consider how the fix should look.

sondregj · 4y ago
Structured data for AI agents

Repository: sindresorhus/clear-module. Description: Clear a module from the cache Stars: 183, Forks: 18. Primary language: JavaScript. Languages: JavaScript (98.6%), TypeScript (1.4%). License: MIT. Latest release: v4.1.3 (5mo ago). Open PRs: 0, open issues: 3. Last activity: 5mo ago. Community health: 71%. Top contributors: sindresorhus, omrilotan, BendingBender, mrchief, Richienb, sondregj.