Skip to content

Workspace dependency used only through a package.json imports alias is reported as unused #2952

Description

@azu

What happened?

When a package imports a workspace package only through a package.json imports (#...) alias, the import resolves correctly and the imported export is treated as used, but the workspace package itself is reported as an unused dependency.

Possible cause

In try_package_imports_fallback in v3.30.0, external targets become NpmPackage, while internal targets become InternalPackageModule using the importing manifest's name. This appears to lose the target workspace package identity needed to credit the dependency.

Additional context

We import every workspace package through an imports alias ("#acme/log/*": "@acme/lib-log/*") so that application code does not depend on package names. In our monorepo this reports 99 workspace dependencies as unused. The workaround is to list each package in ignoreDependencies, which only accepts exact names.

We are also requesting glob support in ignoreDependencies in #2953 to reduce the maintenance cost of this workaround. That is a separate configuration enhancement; this issue asks for the used workspace dependency to be recognized without an ignore.

Related: #56 (support for package.json imports aliases; resolution itself works in this reproduction).

Reproduction

Create the following files in a new directory:

package.json
  { "name": "root", "private": true }

pnpm-workspace.yaml
  packages: ["packages/*"]

packages/lib/package.json
  { "name": "@repro/lib", "type": "module", "exports": { "./*": "./src/*.ts" } }

packages/lib/src/hello.ts
  export const hello = () => "hello";

packages/app/package.json
  {
    "name": "@repro/app",
    "type": "module",
    "private": true,
    "imports": { "#lib/*": "@repro/lib/*" },
    "dependencies": { "@repro/lib": "workspace:*" },
    "exports": { ".": "./src/index.ts" }
  }

packages/app/src/index.ts
  import { hello } from "#lib/hello";
  console.log(hello());

Run from the root directory:

$ pnpm install
$ fallow dead-code
● Unused dependencies (1)
  @repro/lib (packages/app/package.json)

Expected behavior

@repro/lib is credited as used by @repro/app, the same as when an imports alias points to an external npm package. hello is already treated as used, so only the dependency credit is missing.

Fallow version

3.30.0

Operating system

Linux

Configuration

None (default config).

Activity

  1. added
    bugSomething isn't working
    on Sep 27, 2026
  2. added a commit that references this issue on Sep 28, 2026
    8473c38
  3. BartWaardenburg commented on Sep 30, 2026

    @BartWaardenburg
    Collaborator

    @repro/lib no longer shows as an unused dependency in fallow 3.31.0. The #lib/hello import resolves through the install symlink to the source of @repro/lib, and fallow now credits that workspace package, the same as a direct @repro/lib/hello import. The graph cache version changes, so the next run rebuilds the cached import resolution.

    A related change is in the same release. When a package imports an undeclared workspace package, directly or through an alias, fallow now reports an unlisted dependency.

    Install it with npm install fallow@3.31.0. Thank you for the report and the minimal reproduction.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions