Skip to content

A package.json without a name inside a dependency makes its symbols anonymous #525

Closed

Description

@mokevnin

What happens

A file under a nested package.json that has no name gets the anonymous package . ., even though a package.json with a name sits higher up. Published packages often have such files only to set the module type, for example {"type": "module"} in esm/.

That loses which package a symbol belongs to. Different packages can also end up with the same symbol: @simplewebauthn/browser/esm/index.d.ts and hono/dist/types/index.d.ts are both scip-typescript npm . . index.d.ts/.

Reproduction

scip-typescript 0.5.2. package.json:

{"name": "repro", "version": "1.0.0", "type": "module",
 "dependencies": {"zod": "4.1.12", "@simplewebauthn/browser": "14.0.0", "hono": "4.10.4"}}

src/a.ts (with a tsconfig.json using "moduleResolution": "nodenext"):

import { z } from 'zod'
import { startAuthentication } from '@simplewebauthn/browser'
import { Hono } from 'hono'
export const s = z.string(); export const f = startAuthentication; export const h = new Hono()

scip-typescript index emits, among others:

scip-typescript npm . . `external.d.cts`/                                         (zod/v4/classic/package.json)
scip-typescript npm . . `schemas.d.cts`/string().
scip-typescript npm . . methods/`startAuthentication.d.ts`/startAuthentication().  (@simplewebauthn/browser/esm/package.json)
scip-typescript npm . . `index.d.ts`/                                              (both packages)
scip-typescript npm . . `hono.d.ts`/Hono#                                          (hono/dist/types/package.json)

Each of these directories has a package.json without name: {"type": "module"}, {"type": "commonjs"}, or zod's {"type", "main", "module", "types"}.

Expected

Packages.symbol passes over a package.json that has no name and keeps looking in the parent directories, the way Node does when it resolves a package's name. The symbols above would then be scip-typescript npm zod 4.1.12 v4/classic/external.d.cts/, scip-typescript npm hono 4.10.4 dist/types/hono.d.ts/Hono#, and so on.

Right now src/Packages.ts returns ScipSymbol.anonymousPackage() as soon as it finds a package.json that has no string name ("Fallback to an anonymous package because we found a package.json but were unable to parse the name and version"). The anonymous package could be kept for when no named package.json exists up to the project root.

Impact

Tools that read the index to tell which npm package a file depends on (cross-repository navigation, dependency checks) can't attribute these symbols. We hit this in easement and now recover the package from the import's string literal, but that can't work for uses of names like z.string().

Activity

  1. linear-code commented on Nov 2, 2026

    @linear-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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions