Skip to content

@colbymchenry/codegraph cannot be imported as a library on any platform #342

@ayu-exorcist

Description

@ayu-exorcist

@colbymchenry/codegraph cannot be imported as a library on any platform

Problem

The npm thin-installer package (@colbymchenry/codegraph) currently ships only a CLI shim (npm-shim.js). It has no main, no types, and no exports field in its published package.json. This means:

  1. import type { CodeGraph } from "@colbymchenry/codegraph" fails — TypeScript cannot resolve any types from the package.
  2. import { CodeGraph } from "@colbymchenry/codegraph" fails at runtime — there is no JS entry point; the package only exposes a bin script.

As a workaround, downstream projects (e.g. Pi extensions, MCP servers, or any Node.js consumer) currently hard-code a platform-specific deep path:

import type {
  CodeGraph,
  Node,
  NodeKind,
  Edge,
  SearchResult,
} from "@colbymchenry/codegraph-win32-x64/lib/dist/index";

This is brittle and breaks on every platform except Windows x64, because npm skips optionalDependencies that do not match the host os/cpu. On macOS and Linux, the win32-x64 package is never installed, so TypeScript reports:

error TS2307: Cannot find module '@colbymchenry/codegraph-win32-x64/lib/dist/index' or its corresponding type declarations.

Impact

  • TypeScript consumers (Pi extensions, VS Code extensions, test suites) need tsconfig.json paths workarounds that list all six platform packages in priority order.
  • Runtime consumers must manually require.resolve a deep path like @colbymchenry/codegraph-darwin-arm64/lib/dist/index.js instead of using the package name.
  • CI / cross-platform builds fail because the hard-coded path only exists on one platform.

Steps to Reproduce

  1. On macOS or Linux, install the package:

    npm install @colbymchenry/codegraph
  2. Create test.ts:

    import type { CodeGraph } from "@colbymchenry/codegraph";
  3. Run tsc --noEmit:

    error TS2307: Cannot find module '@colbymchenry/codegraph' or its corresponding type declarations.
    
  4. Alternatively, try the hard-coded workaround from the README examples:

    import type { CodeGraph } from "@colbymchenry/codegraph-win32-x64/lib/dist/index";

    This fails on macOS because the win32-x64 optional dependency is not installed.

Environment

  • @colbymchenry/codegraph: 0.9.3 (and all previous versions)
  • Node.js: >= 20
  • OS: darwin-arm64, darwin-x64, linux-x64, linux-arm64, win32-x64, win32-arm64

Proposed Solution

See PR #343. In short:

  1. Add main / types / exports to every platform package (@colbymchenry/codegraph-<target>) so each can be imported directly without deep paths.
  2. Copy the .d.ts tree from the first platform bundle into the main shim package so TypeScript can resolve types from @colbymchenry/codegraph itself.
  3. Generate a small CJS proxy (index.js) in the main shim that resolves the matching platform package at require() time and re-exports everything.
  4. Update the main shim package.json with main, types, and exports (types / require / default conditions).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions