Skip to content

πŸ› Unused subpaths: test-only #imports reported in --production modeΒ #2342

Closed
BipoXDXD/GoblinShift
#475

Description

@dnalborczyk

Thanks for adding the unused subpath imports check in 6.45.0 (#2317), it's a useful one.

In --production mode, a package.json#imports key that is only referenced from test files gets reported as an unused subpath. The default (non-production) run correctly sees the references and reports nothing.

Reproduction

package.json:

{
  "name": "repro",
  "type": "module",
  "imports": {
    "#lib/*": "./src/lib/*",
    "#test/*": "./src/test/*"
  }
}

knip.json:

{
  "entry": ["src/index.ts!"],
  "project": ["src/**/*.ts!"]
}
  • src/index.ts imports from #lib/math.ts
  • src/math.test.ts imports from #lib/math.ts and #test/fixtures.ts
$ knip
βœ‚οΈ  Excellent, Knip found no issues.

$ knip --production
Unused subpaths (1)
#test/*  package.json:6:6

Expected

No issue in --production mode. An imports entry is module-resolution config, not shipped code, so I'd expect it to be treated like a devDependency: if only non-production files reference it, production mode shouldn't call it unused. There's also no change that satisfies the check: removing #test/* breaks the tests.

Workarounds

  • knip --production --exclude subpaths, or ignoreIssues: { "package.json": ["subpaths"] }. Both turn the check off for every key, not just the test-only one.

Two things that would help, either on its own would be enough:

  1. In --production, skip imports keys that are referenced only from non-production files.
  2. A way to ignore individual subpath keys (similar to ignoreDependencies).

knip 6.45.0, Node 26.13.0.

Activity

  1. github-actions commented on Nov 11, 2026

    @github-actions

    Preview release available:

    npm i -D https://pkg.pr.new/knip@f4e3126
  2. webpro commented on Nov 11, 2026

    @webpro
    Member

    Thanks for the report! Fix (skip subpath imports in production mode) should go out soon.

  3. webpro commented on Nov 11, 2026

    @webpro
    Member

    πŸš€ This issue has been resolved in v6.45.1. See Release 6.45.1 for release notes.

    Using Knip in a commercial project? Please consider becoming a sponsor.

  4. added a commit that references this issue on Nov 11, 2026
    f4e3126
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions