Skip to content

Entry Files

Entry files are the starting point for Knip to determine what files are used in the codebase. More entry files lead to increased coverage of the codebase. This also leads to more dependencies to be discovered. This page explains how Knip and its plugins try to find entry files so you don’t need to configure them yourself.

For brevity, the default configuration on the previous page mentions only index.js and index.ts, but the default set of file names and extensions is actually a bit larger:

  • index, main and cli
  • js, mjs, cjs, jsx, ts, mts, cts and tsx

This means files like main.cjs and src/cli.ts are automatically added as entry files. Here’s the default configuration in full:

{
"entry": [
"{index,cli,main}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
"src/{index,cli,main}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}"
],
"project": ["**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}!"]
}

Next to the default locations, Knip looks for entry files in other places. In a monorepo, this is done for each workspace separately.

The values you set override the default values, they are not merged.

Plugins often add entry files. For instance, the Remix, Storybook and Vitest plugins add additional entry files. See the next page about plugins for more details about this.

The package.json is scanned for entry files. The main, bin, and exports fields may contain entry files. The scripts are also parsed to find entry files and dependencies. See Script Parser for more details.

Knip respects .gitignore files. By default, ignored files are not added as entry files. This behavior can be disabled by using the --no-gitignore flag on the CLI.

See configuring project files for guidance on tuning entry and project and when to use ignore.

Putting it together, Knip discovers entry files from:

  • Default locations such as index.js and src/index.ts
  • The main, bin and exports fields in package.json
  • Entry and config files added by enabled plugins (the config files are entry files too)
  • Dynamic imports: require() and import()
  • require.resolve() and import.meta.resolve()
  • new URL('./file.js', import.meta.url)
  • new Worker(…) and child_process fork/spawn/execFile when the target is path.join(__dirname, …)
  • module.register('./loader.js') loader registration
  • Scripts the script parser extracts: package.json scripts, CI workflow run commands, and source-code calls (tagged $ templates, node:child_process, execa, nano-spawn)

Entry files are added to the module graph, and module resolution may pull in further entry files recursively until none remain.

ISC License © 2026 Lars Kappert