{"id":11214,"library":"knip","title":"Knip","description":"Knip is a static analysis tool designed to identify and resolve unused dependencies, exports, and files within JavaScript and TypeScript projects. Currently at version 6.4.1, the project maintains an active release cadence, frequently releasing patch and minor updates to enhance plugin support for various ecosystems, including Astro, Vitest, Rspack, Panda CSS, Rolldown, Stencil, Metro, and Storybook, and to improve its core dependency resolution logic. Knip differentiates itself by providing a comprehensive, configurable solution for dead code elimination, which directly contributes to reduced bundle sizes, improved application performance, and streamlined project maintenance through easier refactorings. Its primary function is invoked via a command-line interface, providing clear reports on unused assets. Additionally, Knip exposes types such as `KnipConfiguration` and a `defineConfig` utility for programmatic configuration scenarios, aiding in its integration with advanced build pipelines, CI/CD systems, and custom development tooling, ensuring type-safe configuration. It aims to reduce technical debt by accurately pinpointing unused code and resources.","status":"active","version":"6.4.1","language":"javascript","source_language":"en","source_url":"https://github.com/webpro-nl/knip","tags":["javascript","analysis","analyze","class","cli","dead code","dependencies","detect","devDependencies","typescript"],"install":[{"cmd":"npm install knip","lang":"bash","label":"npm"},{"cmd":"yarn add knip","lang":"bash","label":"yarn"},{"cmd":"pnpm add knip","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required runtime environment for Knip CLI.","package":"node","optional":false}],"imports":[{"note":"Used in knip.ts configuration files to provide type-safe configuration. Primarily an ESM export.","wrong":"const defineConfig = require('knip').defineConfig;","symbol":"defineConfig","correct":"import { defineConfig } from 'knip';"},{"note":"Type-only import for defining Knip's configuration object in TypeScript projects. Use `type` keyword for explicit type import.","wrong":"import { KnipConfig } from 'knip';","symbol":"KnipConfig","correct":"import { type KnipConfig } from 'knip';"}],"quickstart":{"code":"{\n  // package.json\n  \"name\": \"my-project\",\n  \"version\": \"1.0.0\",\n  \"scripts\": {\n    \"knip\": \"knip\"\n  },\n  \"devDependencies\": {\n    \"knip\": \"^6.0.0\"\n  },\n  \"dependencies\": {\n    \"react\": \"18.2.0\" // Example: Will be marked as unused by Knip\n  }\n}\n\n// knip.ts (create this file in your project root)\nimport { defineConfig, type KnipConfig } from 'knip';\n\nconst config: KnipConfig = defineConfig({\n  // Specify entry files for your application\n  entry: ['src/index.ts', 'src/**/*.{jsx,tsx}'],\n  // Specify project files to analyze\n  project: ['src/**/*.{ts,tsx,js,jsx}'],\n  // Ignore specific files or patterns (e.g., test files, generated code)\n  ignore: ['src/**/*.test.ts', 'dist/**/*', 'node_modules/**/*'],\n  // Enable or disable specific rules, or set thresholds (error, warn, off)\n  rules: {\n    unusedDependencies: 'error',\n    unusedFiles: 'error',\n    unusedExports: 'warn'\n  },\n  // Enable plugins for specific ecosystems (e.g., React, Vitest)\n  plugins: {\n    react: true,\n    typescript: { config: 'tsconfig.json' } // Default, but can be explicit\n  }\n});\n\nexport default config;\n\n// To run Knip:\n// npm install --save-dev knip\n// npm run knip\n","lang":"typescript","description":"Sets up Knip in a TypeScript project with a `knip.ts` configuration, defines basic entry points and rules, and demonstrates running it via `npm run knip`."},"warnings":[{"fix":"Ensure your Node.js environment meets the minimum requirement of `^20.19.0 || >=22.12.0`. Use `nvm` or your preferred Node.js version manager to upgrade.","message":"Knip requires specific Node.js versions. Running with older versions will result in an error and prevent execution.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Carefully review your `knip.ts` configuration, particularly the `entry` and `project` glob patterns. Consult the Knip documentation for best practices regarding monorepo setups and plugin configurations. Use `trace` mode (`knip --trace`) to debug resolution issues.","message":"Incorrect or incomplete configuration of entry points (`entry`) or project files (`project`) in `knip.ts` can lead to false positives (reporting used code as unused) or false negatives (missing actual dead code). This is especially common in complex monorepos or projects with dynamic imports.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Verify that all necessary plugins are explicitly enabled in your `knip.ts` configuration (e.g., `plugins: { react: true, vitest: true }`). If a plugin is missing for a critical technology, consider contributing one or using `ignoreDependencies` as a workaround.","message":"Knip relies on plugins for accurate analysis of specific frameworks, libraries, and build tools. If a relevant plugin is not enabled or properly configured for your project's ecosystem (e.g., React, Vitest, Storybook, Next.js), it may report false positives for dependencies or code used by that technology.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Upgrade your Node.js installation to version `20.19.0` or higher, or `22.12.0` or higher (e.g., `nvm install 20 && nvm use 20`).","cause":"The installed Node.js version on your system does not meet the minimum requirements for Knip.","error":"Error: Knip requires Node.js version ^20.19.0 || >=22.12.0."},{"fix":"Review the `entry` and `project` globs in your `knip.ts` file to ensure they correctly match existing files and directories. Double-check for typos or incorrect paths relative to the project root.","cause":"A file specified in your `knip.ts` `entry` or `project` configuration does not exist or the glob pattern is incorrect.","error":"Entry file '/path/to/my/component.tsx' is not found. Please check your configuration."},{"fix":"Ensure that the relevant Knip plugin for your framework (e.g., `next`, `astro`) is enabled and configured. If a plugin doesn't exist or isn't sufficient, consider adding an `ignoreDependencies` entry for 'my-package' in your `knip.ts`.","cause":"Knip's analysis might not fully understand how 'my-package' is being used due to an unconfigured plugin, complex import patterns, or a specific framework's behavior.","error":"Knip reported dependency 'my-package' as unused, but I'm actively using it in my project."}],"ecosystem":"npm"}