Skip to content

🧩 Knip takes a long amount of time in our codebase #1435

@nandita1

Description

@nandita1

Discuss anything related to Knip

We have a fairly large codebase (around ~121370 lines of code) with a multi package architecture and knip takes around more than 1-1.5 hrs to run whereas depcheck only takes a few minutes. I only want to check for unused dependencies. Also running into OOM issues most of the times in a node.js script even with NODE_OPTIONS="--max-old-space-size=24576". Here is my knip.json file:

{
  "$schema": "https://unpkg.com/knip@5/schema.json",
  "ignore": [
    "**/*.spec.{ts,tsx}",
    "**/*.stories.{ts,tsx}",
    "**/*.test.{ts,tsx}",
    "**/generated/**",
    "**/node_modules/**",
    "**/build_output/**",
    "**/dist/**",
    "tools/**",
    "mock/**",
    ".storybook/**"
  ],
  "ignoreDependencies": ["@types/*", "typescript"],
  "ignoreExportsUsedInFile": true,
  "ignoreWorkspaces": ["tools/**"],
  "workspaces": {
    ".": {
      "entry": [
        "src/index.tsx",
        "config/**/*.{ts,tsx,js,mjs}",
        "vite.*.ts",
        "vite.*.mts",
        "babel.config.js",
        "jest.config.js",
        ".storybook/**/*.{ts,tsx,js}"
      ],
      "ignore": [
        "src/generated/**",
        "build_output/**",
        "dist/**",
        "node_modules/**",
        "**/*.spec.{ts,tsx}",
        "**/*.stories.{ts,tsx}",
        "**/*.test.{ts,tsx}",
        "tools/**",
        "mock/**"
      ],
      "ignoreDependencies": [
        "@types/*",
        "typescript",
        "eslint",
        "prettier",
        "jest",
        "@testing-library/*",
        "vite",
        "babel-*",
        "@babel/*",
        "webpack",
        "webpack-*"
      ],
      "project": [
        "src/**/*.{ts,tsx}",
        "config/**/*.{ts,tsx,js,mjs}",
        "!src/**/*.spec.{ts,tsx}",
        "!src/**/*.stories.{ts,tsx}",
        "!src/**/*.test.{ts,tsx}",
        "!src/generated/**",
        "!**/generated/**",
        "!**/node_modules/**",
        "!**/build_output/**",
        "!**/dist/**"
      ]
    },
    "packages/*": {
      "entry": ["src/index.barrel.tsx", "src/**/*.routes.tsx"],
      "ignore": [
        "generated/**",
        "dist/**",
        "node_modules/**",
        "**/*.spec.{ts,tsx}",
        "**/*.stories.{ts,tsx}",
        "**/*.test.{ts,tsx}"
      ],
      "ignoreDependencies": [
        "@types/*",
        "typescript",
        "eslint",
        "prettier",
        "jest",
        "@testing-library/*"
      ],
      "project": [
        "src/**/*.{ts,tsx}",
        "!src/**/*.spec.{ts,tsx}",
        "!src/**/*.stories.{ts,tsx}",
        "!src/**/*.test.{ts,tsx}",
        "!generated/**",
        "!**/generated/**",
        "!**/node_modules/**",
        "!**/build_output/**",
        "!**/dist/**"
      ]
    },
    "packages/snappables/*": {
      "entry": ["src/index.barrel.tsx", "src/**/*.routes.tsx"],
      "ignore": [
        "generated/**",
        "dist/**",
        "node_modules/**",
        "**/*.spec.{ts,tsx}",
        "**/*.stories.{ts,tsx}",
        "**/*.test.{ts,tsx}"
      ],
      "ignoreDependencies": [
        "@types/*",
        "typescript",
        "eslint",
        "prettier",
        "jest",
        "@testing-library/*"
      ],
      "project": [
        "src/**/*.{ts,tsx}",
        "!src/**/*.spec.{ts,tsx}",
        "!src/**/*.stories.{ts,tsx}",
        "!src/**/*.test.{ts,tsx}",
        "!generated/**",
        "!**/generated/**",
        "!**/node_modules/**",
        "!**/build_output/**",
        "!**/dist/**"
      ]
    }
  }
}

Running the command as - NODE_OPTIONS="--max-old-space-size=24576" npx knip --include=dependencies,devDependencies --reporter json --config knip.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions