knip: š Self-import fails if `exports` points to `dist` (package self referencing)
Prerequisites
- Iām using the latest version
- Iāve read the relevant documentation
- Iāve searched for existing issues
- Iāve checked the list of known issues
- Iāve read the issue reproduction guide
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
exportsmap pointsdistinstead ofsrc
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
- Don't reuse principals with `rootDir` set (resolves #1007) — committed to webpro-nl/knip by webpro 2 years ago
Please see https://github.com/webpro-nl/knip/issues/1015#issuecomment-2766234408, thereāll be a revert/patch.
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
rootDiris 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
distcontains build artifacts and is supposed to be git-ignored. Thatās why Knip tries to find thesrcfile.