Registry / devops / knip
library0.0.3jsnpmunverified

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.

npm install knip
INSTALL
IMPORT
SIG · KNIP
K
knip
devopsjavascriptv0.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

defineConfig
import { defineConfig } from 'knip';
const defineConfig = require('knip').defineConfig;
Used in knip.ts configuration files to provide type-safe configuration. Primarily an ESM export.
KnipConfig
import { type KnipConfig } from 'knip';
import { KnipConfig } from 'knip';
Type-only import for defining Knip's configuration object in TypeScript projects. Use `type` keyword for explicit type import.

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`.

{ // package.json "name": "my-project", "version": "1.0.0", "scripts": { "knip": "knip" }, "devDependencies": { "knip": "^6.0.0" }, "dependencies": { "react": "18.2.0" // Example: Will be marked as unused by Knip } } // knip.ts (create this file in your project root) import { defineConfig, type KnipConfig } from 'knip'; const config: KnipConfig = defineConfig({ // Specify entry files for your application entry: ['src/index.ts', 'src/**/*.{jsx,tsx}'], // Specify project files to analyze project: ['src/**/*.{ts,tsx,js,jsx}'], // Ignore specific files or patterns (e.g., test files, generated code) ignore: ['src/**/*.test.ts', 'dist/**/*', 'node_modules/**/*'], // Enable or disable specific rules, or set thresholds (error, warn, off) rules: { unusedDependencies: 'error', unusedFiles: 'error', unusedExports: 'warn' }, // Enable plugins for specific ecosystems (e.g., React, Vitest) plugins: { react: true, typescript: { config: 'tsconfig.json' } // Default, but can be explicit } }); export default config; // To run Knip: // npm install --save-dev knip // npm run knip
knip --version
Debug
Known issues
breakingKnip requires specific Node.js versions. Running with older versions will result in an error and prevent execution.
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.
affects: >=6.0.0
gotchaIncorrect 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.
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.
affects: >=1.0.0
gotchaKnip 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.
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.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Knip requires Node.js version ^20.19.0 || >=22.12.0.
The installed Node.js version on your system does not meet the minimum requirements for Knip.
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`).
Entry file '/path/to/my/component.tsx' is not found. Please check your configuration.
A file specified in your `knip.ts` `entry` or `project` configuration does not exist or the glob pattern is incorrect.
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.
Knip reported dependency 'my-package' as unused, but I'm actively using it in my project.
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.
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`.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies
noderequiredRequired runtime environment for Knip CLI.
Agent activity
4 hits · last 30 days
node
4
Resources
knip — npm install knip · libregistry