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
6.65k stars 154 forks source link

Knip doesn't enable Vue plugin in Nuxt 🐛 #770

Closed BMFreed closed 1 month ago

BMFreed commented 1 month ago

Prerequisites

Reproduction url

https://codesandbox.io/p/devbox/priceless-aryabhata-zl8s4x?file=%2Fknip.json%3A16%2C2

Reproduction access

Description of the issue

It seems that Knip doesn't enable Vue plugin in Nuxt if Vue isn't explicitly listed in dependencies/devDependencies. In the reproduction URL I tried to enable the Vue plugin manually within knip.json by setting "vue" to true and to the default (as mentioned here) config value, but this doesn't work.

Can this be fixed without needing to add vue to dependencies or devDependencies?

Thanks in advance!

webpro commented 1 month ago

The Vue plugin is enabled, but what we need here is a Nuxt plugin.

webpro commented 1 month ago

Oh, it's in the TS config ("jsxImportSource": "vue"), so it's a referenced dependency from the perspective of the TypeScript plugin.

For now I'd recommended to add "vue" to ignoreDependencies.

BMFreed commented 1 month ago

Oh, it's in the TS config ("jsxImportSource": "vue"), so it's a referenced dependency from the perspective of the TypeScript plugin.

For now I'd recommended to add "vue" to ignoreDependencies.

Thank you for your reply! This solves the problem with Knip reporting Vue as a missing dependency, but the main issue is that if Vue isn't explicitly listed in dependencies/devDependencies - the Vue plugin isn't enabled, so knip doesn't parse Vue files and reports the file "foo.ts" as unused, although it is imported in the .vue file.

Is there a way to forcefully enable the Vue plugin without installing it in the dependencies? For now just installing it as a dev dependency is the only workaround I found in order for Knip to parse Vue files :(

EDIT: seems that specifying "vue: true" in the config does enable the plugin, but somehow without Vue installed (listed in package.json) Knip won't parse .vue files

webpro commented 1 month ago

knip doesn't parse Vue files

AH I didn't catch that.

Is there a way to forcefully enable the Vue plugin without installing it in the dependencies?

So the issue is that vue: true enables the Vue plugin, but not compiling the Vue files. We can just add nuxt here

I can whip up a release soon for this.

BMFreed commented 1 month ago

knip doesn't parse Vue files

AH I didn't catch that.

Is there a way to forcefully enable the Vue plugin without installing it in the dependencies?

So the issue is that vue: true enables the Vue plugin, but not compiling the Vue files. We can just add nuxt here

I can whip up a release soon for this.

Thank you so much! You are a legend!

webpro commented 1 month ago

:rocket: This issue has been resolved in v5.27.5. See Release 5.27.5 for release notes.

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