webpro-nl / knip

✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects. Knip it before you ship it!
https://knip.dev
ISC License
7.06k stars 177 forks source link

🔄 Regression on importing from subdirectory of a package in node_modules #773

Closed stephenwade closed 2 months ago

stephenwade commented 2 months ago

Prerequisites

Reproduction url

https://github.com/stephenwade/knip-issue-repro-crispy-broccoli

Reproduction access

Good version

5.27.3

Bad version

5.27.4

Description of the regression

In my project, I import a type from 'node_modules/react-toastify/dist/components' because 'react-toastify' doesn't export it. To get around Knip reporting it as an unlisted dependency, I added this to my config file:

"ignoreDependencies": ["node_modules/react-toastify/dist/components"]

In version 5.27.3, Knip reports no issues. In version 5.27.4 and later, I get this report:

Unlisted dependencies (1)
node_modules/react-toastify/dist/components  app/ToastContainer.tsx
Configuration issues (1)
Unused item in ignoreDependencies: node_modules/react-toastify/dist/components

I haven't found a configuration that works for my project since the update.

I think the issue is likely caused by 89780376.

(ref: https://github.com/stephenwade/festival/pull/1693)

webpro commented 2 months ago

Regardless of whether this is a bug or not, this seems to work the same for a while:

npx knip@5.0.0
Unlisted dependencies (1)
node_modules/react-toastify/dist/components  app/ToastContainer.tsx

The values in ignoreDependencies are package names so either "name" or "@scope/name" - so in this case the odd "node_modules" would do.

Will investigate some more later on.

stephenwade commented 2 months ago

The issue is not that it appears as an unlisted dependency. The issue is that I can no longer ignore that report with "ignoreDependencies".

webpro commented 2 months ago

You can use literally "ignoreDependencies": ["node_modules"]

stephenwade commented 2 months ago

That works, thank you!

I'll leave the issue open for the underlying issue that Knip should detect this import as react-toastify and not need any "ignoreDependencies" config.

webpro commented 2 months ago

:rocket: This issue has been resolved in v5.30.2. See Release 5.30.2 for release notes.

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