Skip to content

TypeScript ESM imports spelled ./x.js never resolve to x.ts (import-graph recall 0.2% on zod) #3552

Closed

Description

@squid-protocol

Problem

Modern TypeScript under "moduleResolution": "node16"/"nodenext", and every ESM package published from TS, imports a sibling source file by its emitted name: import { metabench } from "./metabench.js" refers to metabench.ts. The TypeScript compiler maps .js → .ts, .jsx → .tsx, .mjs → .mts and .cjs → .cts. The engine's import resolver doesn't, so these imports draw no edge at all.

Measured

tests/tools/import_graph_accuracy.py, merged in #3547, pinned corpus colinhacks/zod@2bf7b06:

resolvable imports engine edges precision recall
599 53 1.9% 0.2%

Nearly all 598 misses are this shape. Examples, checked against the source:

  • packages/bench/array.ts: import { makeData, … } from "./benchUtil.js" → packages/bench/benchUtil.ts, no edge.
  • packages/zod/src/v4/core/schemas.ts: import * as checks from "./checks.js" → checks.ts, no edge.

The 52 edges the engine does draw from these files mostly come from bare package specifiers ("zod/v4/core") matched by basename. For example, packages/bench/*.ts → packages/zod/src/v4/core/core.ts is the #3544 shape.

Impact

For any ESM TypeScript project, the import graph is nearly empty. So PageRank, blast radius, popularity and dependency_density for TS files come out almost entirely wrong. JS projects written as ESM with explicit extensions resolve normally; this is TS-specific.

Fix direction

In network_risk_sensor.py's resolver, for a relative (./ or ../) token whose extension is .js/.jsx/.mjs/.cjs, also try the TS source extensions at the same path (.ts, .tsx, .mts, .cts, .d.ts) after the literal path. Only for relative tokens: a bare specifier stays a package.

Gate: import_graph_accuracy.py typescript should move by hundreds of edges. Lock the gain in with --regenerate, and re-bless golden masters for the TS corpus moves.

Activity

  1. added
    bug
    core-engine
    on Sep 25, 2026
  2. squid-protocol commented on Sep 25, 2026

    @squid-protocol
    OwnerAuthor

    Fixed by #3562 (merged). A ./x.js ESM import now resolves to its x.ts source, and an existing x.js file still takes precedence. On zod, TypeScript import-graph recall went from 0.2% to 100%, with 91.4% precision. CI gates both through import_graph_accuracy.py.


    Generated by Claude Code

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions