knip icon indicating copy to clipboard operation
knip copied to clipboard

🐛 SvelteKit's src/service-worker.{ts,js} is marked as unused

Open gwennlbh opened this issue 7 months ago • 3 comments

Prerequisites

Reproduction url

https://stackblitz.com/edit/vitejs-vite-xdzv7lv3?file=src%2Fservice-worker.ts

Reproduction access

  • [x] I've made sure the reproduction is publicly accessible

Description of the issue

The file src/service-worker.ts, which is special-cased in sveltekit as a auto-registered service worker, is reported as unused by knip.

Moreover, any exported function that is only used in the service worker is reported as unused

Just run npm run knip in a terminal in the repro link. Relevant files are src/service-worker.ts and src/lib/exported.ts

See https://svelte.dev/docs/kit/service-workers

Oh and also, $service-worker is not resolved properly

gwennlbh avatar Jul 02 '25 17:07 gwennlbh

it is even showing .svelte files from $lib/components as unused files though i am actively using them.

ashwin31 avatar Sep 01 '25 14:09 ashwin31

maybe sveltekit or svelte support need to be added.

ashwin31 avatar Sep 01 '25 14:09 ashwin31

Someone could extend the existing Svelte plugin.

webpro avatar Dec 27 '25 06:12 webpro

Preview release available:

npm i -D https://pkg.pr.new/knip@c0ed40a

github-actions[bot] avatar Jan 13 '26 20:01 github-actions[bot]

Any chance someone could give the preview release a shot and see if it behaves as expected?

webpro avatar Jan 13 '26 20:01 webpro

:rocket: This issue has been resolved in v5.81.0. See Release 5.81.0 for release notes.

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

webpro avatar Jan 14 '26 07:01 webpro