knip: šŸ› Self-import fails if `exports` points to `dist` (package self referencing)

Prerequisites

Reproduction url

https://stackblitz.com/edit/github-vuf1gm32?file=packages%2Fshared%2Fpackage.json

Reproduction access

  • I’ve made sure the reproduction is publicly accessible

Description of the issue

Setup:

  • package has self-referencing imports
  • exports map points dist instead of src

knip does not detect the file as used.

Note that if I use the relative import (import "./beta.js") it’s detected correctly.


I found out now that I finally got around to enabling includeEntryExports (thanks!) but it seems that it also fails without it. I think that’s an unrelated issue though:

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Alright. I was afk and source mapping is not failing, but now that I’ve actually looked into it, it seems there was a bug with module resolution in general. Knip tries to reuse TS programs and it should not do that if rootDir is set. Should be good in the next release!

This case boils down to something I’ve dubbed ā€œsource mappingā€: https://knip.dev/features/monorepos-and-workspaces#source-mapping

The idea is that dist contains build artifacts and is supposed to be git-ignored. That’s why Knip tries to find the src file.