Skip to content

🔄 --tsConfig paths are not used for module resolution in v6 #1794

Description

@agneym

Prerequisites

Reproduction url

https://github.com/agneym/knip-v6-tsconfig-paths-repro

Reproduction access

  • I've made sure the reproduction is publicly accessible

Good version

5.64.0

Bad version

6.0.0 and still present in latest 6.16.1

Description of the regression

In Knip v5, --tsConfig tsconfig.app.json used that tsconfig's compilerOptions.paths for module resolution. In Knip v6, the selected tsconfig is loaded, but its compilerOptions.paths do not appear to be used for resolving imports in discovery mode.

Repro commands:

git clone https://github.com/agneym/knip-v6-tsconfig-paths-repro.git
cd knip-v6-tsconfig-paths-repro
pnpm install
pnpm knip

The repo has this shape:

  • tsconfig.json has no compilerOptions.paths.
  • tsconfig.app.json extends tsconfig.json and defines @app/* -> ./src/*.
  • knip.ts has no paths.
  • src/main.ts imports src/used.ts via @app/used.
  • src/unused.ts is truly unused.

Expected with:

knip --include files --tsConfig tsconfig.app.json --no-progress --reporter compact

Only the truly unused file should be reported:

src/unused.ts

Actual with Knip v6.16.1:

src/unused.ts: src/unused.ts
src/used.ts: src/used.ts

If I duplicate the alias in Knip config via paths, then v6 reports only src/unused.ts, which suggests the import itself is fine and the issue is specifically that compilerOptions.paths from the selected --tsConfig file is not feeding module resolution.

Confirmed regression:

pnpm dlx knip@5.64.0 --include files --tsConfig tsconfig.app.json --no-progress --reporter compact

reports only:

src/unused.ts

while:

pnpm dlx knip@6.0.0 --include files --tsConfig tsconfig.app.json --no-progress --reporter compact

reports both files.

Note: --use-tsconfig-files reporting no unused files is not the concern here; the FAQ explains that tsconfig files become program files and are not reported as unused. This regression is about normal discovery mode with --tsConfig not using the selected tsconfig's compilerOptions.paths for module resolution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions