-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Imports with foreign file extensions fail with "Unable to find" file error #623
Comments
Thanks for the report @peplin, but I do need a reproduction, otherwise there's nothing to test against. There's some coverage already, so similar imports give no issues (e.g. https://github.com/webpro/knip/blob/main/packages/knip/fixtures/module-resolution-non-std/src/index.ts) |
I don't know what I was doing wrong yesterday, but this morning I was able to create a minimal repro: https://stackblitz.com/edit/github-8sedwy One potential clue: this is happening in an npm workspace. When you run |
This is an bit of an odd repro. Knip is supposed to be installed in the root workspace. And perhaps the culprit is that there's an |
I updated the repro to move |
My main point remains: when inside the |
That's unfortunate, especially because it worked in prior releases. Why would we only have this problem with foreign files, like SVG and .scss? It seems like knip is very close to supporting absolute imports We intentionally have our workspaces configured to only allow absolute imports, so if those won't be supported by knip officially, would you recommend adding custom no-op compilers for all forieng files as a workaround? |
Knip should support "absolute" imports like TypeScript does, but it doesn't (and shouldn't) support "crossing boundaries" of workspaces like this. I'd expect the same issue for any file. In general my recommendation would be to separate workspaces properly to group dependencies in workspaces, to group reported issues, etc etc. Personally I would not even recommend such "absolute" imports, but that's yet another discussion. |
Thanks for the clarification. I don't think I understand what you mean by crossing boundaries. I updated the repro to have 2 separate workspaces to avoid the problem of importing
I narrowed it down further: the problem was introduced in 47ff3eb. The new resolver resolves a file if it finds an exact match with the imported path. That causes it to be treated as an internal import by knip, and we get the internal error when knip is surprised not to find the file in the file manager. Previuosly, when |
Alright, you're not giving up, I like that. By "crossing boundaries" I mean that if you are inside the If something "works" doesn't always necessarily mean it's a good idea. What we are combining here are two separate things: module resolution (TypeScript) and workspaces (dependency management). E.g. if module resolution works as expected we can still publish broken packages, or vice versa. Now that we got this far I'll try and look into it soon. |
I've ensured that Knip does no longer throw as reported.
For details, also see this fixture and what issues it reports: |
🚀 This issue has been resolved in v5.13.0. See Release 5.13.0 for release notes. Using Knip in a commercial project? Please consider sponsoring me. |
Thank you! |
Thanks for the report, there was definitely a bug in Knip |
When upgrading from 5.0.1 to 5.12.1, I am running into a new problem with imports of foreign files, e.g. .svg, .webp, and .scss.
As an example, there is a file
client/src/components/pages/settings/login-logo.tsx
with:When I run the newer version of
knip
(5.12.1), it exits with an internal error:From instrumenting the code with a few debug statements, I found that the issues is triggered when the TypeScript
getResolvedModule(...)
function returns a module for this import.knip
eventually tries to load the source file for this module, but it doesn't exist in the file manager.I've tried but so far failed to create a minimal reproduction repo. There must be an edge case in my particular private monorepo that's triggering this bug. In all of my repro attempts so far, the
.svg
is not resolved to a module, so the problematic code is never triggered.I was able to work around this by adding custom no-op compilers (as mentioned in #504), but I gather from the code that these foreign file types are supposed to be automatically excluded. The issue also goes away if I comment out this line.
The text was updated successfully, but these errors were encountered: