Skip to content

module: rebase clearCache and address review comments - #27

Draft
anonrig wants to merge 3 commits into
mainfrom
cursor/module-clear-cache-68bc
Draft

module: rebase clearCache and address review comments#27
anonrig wants to merge 3 commits into
mainfrom
cursor/module-clear-cache-68bc

Conversation

@anonrig

@anonrig anonrig commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Updates the module.clearCache work from nodejs/node#61767 after rebasing onto current main and addressing the remaining review threads.

Rebase

Rebased yagiz/node-module-clear-cache onto origin/main. Conflicts were in:

  • lib/internal/modules/esm/translators.js — kept main's loadCJSModuleWithModuleLoad (translateContext, hook skip, patched _load export mirroring) and re-installed the CJS cache entry when clearCache races an in-flight import().
  • lib/internal/modules/helpers.js — exported both getRequireStack (from main) and getFilePathFromFileURL (from this change).

The original PR branch yagiz/node-module-clear-cache was force-pushed with the same commits so nodejs/node#61767 is updated.

Review comments addressed

Unresolved threads from joyeecheung, jsumners-nr, and related conversation comments:

  • Docs: parentURL and resolver are documented as required. Added relative, bare, and absolute-URL examples. Clarified there is no recursive option. Rewrote the memory-retention section so it talks about user-module references (for example static import) rather than ModuleWrap / V8 internals. Added a CommonJS test-reload example.
  • resolver: 'require' + URL: throws ERR_INVALID_ARG_TYPE. String specifiers that look like file: URLs are still treated as paths, matching require().
  • kLinkedRequestsSlot: cleared after successful ModuleWrap instantiation so imported wraps are not pinned after they leave Node.js caches.
  • Tests: stopped asserting on internal resolve-cache helpers and private parent symbols; those tests now check reload behavior and GC collectability. Hash-map test comments no longer name hash_to_module_map.

Recursive cache clearing was not added (see laverdet's comment on that thread).

Testing

ESLint on the changed JS/test files and doc/api/module.md is clean. lint-md on doc/api/module.md is clean. A full Node.js rebuild is still needed to run the test/parallel/test-module-clear-cache* and test/es-module/test-module-clear-cache* suites, and to exercise the C++ kLinkedRequestsSlot change.

Open in Web Open in Cursor 

anonrig and others added 3 commits August 21, 2026 00:47
Document required parentURL/resolver, non-absolute specifier examples,
and that clearCache does not follow user-module links or recurse.

Reject URL objects when resolver is require, drop linked ModuleWrap
references after successful instantiation, and stop testing internals
in the clearCache suite.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
Remove an unused eslint-disable in the reload example and place the
ECMA-262 heading reference in alphabetical order.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6b903ee. Configure here.


const parent = parentPath ? createParentModuleForClearCache(parentPath) : null;
try {
const { filename, format } = resolveForCJSWithHooks(specifier, parent, false, false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require clearCache silently no-ops

High Severity

resolveForCJSWithHooks is called with false as the fourth argument, but that parameter is now a destructured options object. Destructuring false throws, and the surrounding catch turns that into null, so every resolver: 'require' clearCache call silently skips clearing CJS and related caches.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6b903ee. Configure here.

// Re-install so wrapModuleLoad finds the same module instance.
if (CJSModule._cache[filename] !== module) {
CJSModule._cache[filename] = module;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Race overwrites newer CJS cache

Medium Severity

The in-flight import() race fix reassigns Module._cache[filename] whenever it is not the current module, including when a newer post-clearCache load already owns that slot. Concurrent clear-then-reimport can clobber the fresh cache entry and produce split or flaky module instances.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6b903ee. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants