Getting Started
Requirements
Section titled “Requirements”Knip v5 requires at least Node.js v18.18.0. Or Bun.
Want to try Knip without installation? Visit the playground.
Installation
Section titled “Installation”This is the easiest and recommended way to install Knip:
npm init @knip/configpnpm create @knip/configbun create @knip/configyarn create @knip/configNow you can run Knip to lint your project:
npm run knippnpm knipbun knipyarn knipKnip will lint your project and report unused dependencies, exports and files.
If the output makes sense to you, feel free to go to the next page: configuration.
Too Much?
Section titled “Too Much?”In large or complex codebases the output might be overwhelming. Start by limiting the number of shown issues per type:
npm run knip -- --max-show-issues 5pnpm knip --max-show-issues 5bun knip --max-show-issues 5yarn knip --max-show-issues 5The output is easier to digest and may include some configuration hints to get an idea of what’s left to configure. Many unused files? Go to configuration and follow up with troubleshooting if needed.
Manual
Section titled “Manual”Alternatively, manually install Knip using your package manager:
npm install -D knip typescript @types/nodepnpm add -D knip typescript @types/nodebun add -D knip typescript @types/nodeyarn add -D knip typescript @types/nodeKnip uses typescript and @types/node as peer dependencies to increase
compatibility with your project. No worries, they’re probably in your
node_modules already.
Then add a knip script to your package.json:
{ "name": "my-project", "scripts": { "knip": "knip" }}Without installation
Section titled “Without installation”To run Knip without adding it to your project:
npx knippnpm dlx knipbunx knipIn this scenario typescript and @types/node are expected to be installed
already.
ISC License © 2024 Lars Kappert