GitShow/sindresorhus/clear-module
sindresorhus

clear-module

Clear a module from the cache

by sindresorhus
Star on GitHubForknpm

JavaScript

184 stars18 forks6 contributorsActive · 1mo agoSince 2014MIT

Meet the team

See all 6 on GitHub →
sindresorhus
sindresorhus25 contributions
omrilotan
omrilotan3 contributions
BendingBender
BendingBender1 contribution
mrchief
mrchief1 contribution
Richienb
Richienb1 contribution
sondregj
sondregj1 contribution

Languages

View on GitHub →
JavaScript98.6%
TypeScript1.4%

Community health

4 of 6 standards met

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

Recent PRs & issues

Active · 3 discussions · Last activity 1mo ago
See all on GitHub →
MCArth
clear-module does not clear modules deep in the stack traceOpenIssue

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 · 2y ago
sindresorhus
Add `filter` optionOpenIssue

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

Recent fixes

View closed PRs →
Fadoli
BUG : Clear-module doesn't skip native moduleClosedIssue

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 · 1mo ago
Jah-yee
fix: skip native modules (.node files) to prevent 'Unknown failure' on re-requireMergedPR

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 · 1mo ago
sondregj
Fix for certain child modules not getting clearedMergedPR

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: 184, Forks: 18. Primary language: JavaScript. Languages: JavaScript (98.6%), TypeScript (1.4%). License: MIT. Open PRs: 0, open issues: 3. Last activity: 1mo ago. Community health: 71%. Top contributors: sindresorhus, omrilotan, BendingBender, mrchief, Richienb, sondregj.

·@ofershap

Replace github.com with gitshow.dev