Repository navigation
Description
Version: graphify 0.9.37 (also observed on 0.9.32)
Platform: Windows 11, Python 3.14.6, uv tool install "graphifyy[mcp]"
Summary
A CommonJS require() written directly inside a function body (nesting depth 1) produces no edge at all — not a dangling one, not a low-confidence one. The importing file ends up with zero connection to the module it requires. The identical require() at module scope resolves fine, so a codebase can look well-connected while every deferred require is invisible.
This matters disproportionately because lazy require() is the standard CommonJS idiom for breaking circular dependencies. The edges most likely to be dropped are exactly the ones describing a project's most tangled relationships.
There is an irony worth flagging: graphify labels edges EXTRACTED (explicit in source) vs INFERRED (resolved heuristically). A literal require('./target') string is about as EXTRACTED as evidence gets — yet in the repro below the lazy-require file keeps an INFERRED 0.5-confidence edge while its four EXTRACTED 1.0-confidence edges vanish.
Reproduction
Three files, no config, no aliases, no bundler. git init + graphify extract . --code-only.
// target.js
function helper() { return 42; }
module.exports = { helper };// top_level.js — require at module scope (CONTROL)
const { helper } = require('./target');
function useIt() { return helper(); }
module.exports = { useIt };// in_function.js — same require, one level deeper
function useItLazily() {
const { helper } = require('./target');
return helper();
}
module.exports = { useItLazily };Result — 7 nodes, 7 edges
top_level.js → four EXTRACTED edges, confidence 1.0:
{"relation":"imports_from","confidence":"EXTRACTED","confidence_score":1,"source":"top_level","target":"target","source_location":"L1"}
{"relation":"imports","confidence":"EXTRACTED","confidence_score":1,"source":"top_level","target":"target_helper","source_location":"L1"}
{"relation":"calls","confidence":"EXTRACTED","confidence_score":1,"source":"top_level_useit","target":"target_helper","source_location":"L2"}
{"relation":"contains","confidence":"EXTRACTED","confidence_score":1,"source":"top_level","target":"top_level_helper","source_location":"L1"}in_function.js → one INFERRED edge, confidence 0.5, pointing at its own function:
{"relation":"indirect_call","confidence":"INFERRED","confidence_score":0.5,"source":"in_function","target":"in_function_useitlazily","source_location":"L5"}| file | require placement |
edge to target |
|---|---|---|
top_level.js |
module scope | ✅ imports_from + imports |
in_function.js |
depth-1 function body | ❌ none |
Also note top_level_helper exists as a node (the destructured binding) while in_function has no equivalent — the binding is not extracted either.
Why this is distinct from existing issues
- JS/TS:
await import('…')inside a nested function produces no edge — andaffectedcannot traversedynamic_importat all #2575 (await import('…')inside a nested function produces no edge) — that report states explicitly that a dynamic import at the top level of a function resolves fine, and that nesting (function-inside-function, depth ≥2) is the trigger. Here the failure is at depth 1 with CommonJSrequire(), not ESMimport(). Possibly a shared root cause in scope walking, but a different syntax node and a different depth threshold, so it will not be fixed or verified by the same test. - JS/TS:
affectedcannot traverse a dynamicimport('…')made inside a function — edge exists, blast radius is short by 20% #2584 (affectedcannot traverse a dynamicimport()made inside a function) — there the edge exists and traversal is the problem. Here no edge is ever created. - Python AST import edges to in-repo modules emit bare module names, silently dropping real dependencies #2280 / Elixir: imports edges target a bare module id that matches no node — every cross-module import edge is silently dropped at build (2,586 of 19,337 on a 900-file project) #2556 (bare module-name endpoints that dangle and are dropped at build) — those produce an edge with an unmatchable endpoint. Here nothing is emitted at all; there is no dangling endpoint to resolve.
- JS: jsconfig.json baseUrl not honoured — non-relative imports (static AND dynamic) produce no edge, orphaning every module in a Rails/webpacker app #2153 (
jsconfigbaseUrl, non-relative specifiers) — the repro above uses a plain relative./targetspecifier with no config of any kind.
Real-world impact
Found while indexing BourbonDog/amicus (~841 JS files). Benchmarking graphify affected against plain grep for one module's dependents:
- graphify found 3 of 6 real
require()-backed dependents;grepfound all 6 in under a second - the 3 missed (
headless.js,mcp-server.js,sidecar/session-utils.js) all require the target from inside a function body --depth 4did not recover them, confirming this is missing edges rather than traversal depth
That codebase has 9 circular-dependency chains that are deliberately broken by lazy require(), each with a source comment saying so (// lazy: avoids a load-time cycle). Every one of those cycle-breaking edges is absent from the graph — so the graph presents an acyclic module structure that does not match the code.
The practical consequence is that affected under-reports blast radius without signalling reduced confidence, which is the dangerous direction for a "what breaks if I change this?" tool.
Suggested direction
Walk call_expression nodes with callee require at any scope depth rather than only at module scope, mirroring whatever the ESM path does for static imports. Two things worth covering in tests, since the amicus corpus exercises both:
require()insidetry { }within a function (very common for optional/fallback loads)- multiple
require()calls of the same module in different functions of one file (should dedupe to one edge, not zero)
Happy to test a patch against the amicus corpus — it has ~50 lazy requires across 9 documented cycles, so it is a decent real-world fixture for this.
Activity
fix(js): retain lazy CommonJS require dependencies (#2700)
test(js): cover dynamic-require skip and no-double-count for lazy req…
chore: bump to 0.9.44
safishamsi commentedon Aug 15, 2026
Fixed in v0.9.44 (on PyPI now) via #2749, thanks @rajanpanth. Closing.