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 discover entry files so you don’t have to configure them yourself.
Default entry file patterns
Section titled “Default entry file patterns”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,mainandclijs,mjs,cjs,jsx,ts,mts,ctsandtsx
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}!"]}In addition to the default locations, Knip looks for entry files in other
places. In a monorepo, this is done for each workspace separately.
Custom entry and project values replace these defaults, they are not merged.
Entry files from the other places on this page are still added.
Plugins
Section titled “Plugins”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.
Scripts in package.json
Section titled “Scripts in package.json”The package.json is scanned for entry files. The main, module, browser,
bin, types, typings and exports fields may contain entry files. These
are added even when entry is customized. The targets of a key in the imports
field (subpath imports) are entry files only when the key is imported somewhere;
otherwise the key is reported as an unused subpath. With
includeSubpathExports the same applies to the exports field. The
scripts are also parsed to find entry files and dependencies. See Script
Parser for more details.
Ignored files
Section titled “Ignored files”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.
Configuring project files
Section titled “Configuring project files”See configuring project files for guidance on tuning entry and project
and when to use ignore.
Where Knip looks for entry files
Section titled “Where Knip looks for entry files”Putting it together, Knip discovers entry files from:
- Default locations such as
index.jsandsrc/index.ts - The
main,bin,exportsand other fields inpackage.json - Entry and config files added by enabled plugins (the config files are entry files too)
- Dynamic imports:
require()andimport() require.resolve()andimport.meta.resolve()new URL('./file.js', import.meta.url)new Worker(…)andchild_processfork/spawn/execFilewhen the target ispath.join(__dirname, …)module.register('./loader.js')loader registration- Scripts the script parser extracts:
package.jsonscripts, CI workflowruncommands, 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 © 2026Lars Kappert