Known Issues
List of known issues and workarounds for exceptions thrown during a Knip run.
See handling issues to learn more about dealing with lint issues.
Exceptions from config files
Section titled “Exceptions from config files”An exception may be thrown when a Knip plugin loads a JavaScript or TypeScript
configuration file such as webpack.config.js or vite.config.ts:
$ knipError loading .../vite.config.tsKnip may load such files differently, in a different environment, with missing
environment variables, missing path aliases, etcetera. Use --debug to locate
the cause of the issue with more details.
Potential workarounds:
- Set path aliases for “Cannot find module” errors
- Set missing environment variable(s), potential solutions:
- Use a helper package like dotenvx
KEY=VAL knipnode --env-file .env $(which knip)
- Disable loading the file by overriding the default
configfor that plugin.- Example:
vite: { config: [] } - In a monorepo, be more specific like so:
workspaces: { "packages/lib": { vite: { config: [] } } } - If this helps, add the file as an
entryfile for static analysis.
- Example:
- Disable the related plugin.
- Example:
eslint: false - In a monorepo, be more specific like so:
workspaces: { "packages/lib": { eslint: false } } - If this helps, add the file as an
entryfile for static analysis.
- Example:
- As a last resort, ignore the workspace:
ignoreWorkspaces: ["packages/lib"].
Path aliases in config files
Section titled “Path aliases in config files”Loading the configuration file (e.g. cypress.config.ts) for one of Knip’s
plugins may give an error:
$ knipAnalyzing workspace ....Error loading .../cypress.config.tsReason: Cannot find module '@alias/name'Require stack:- .../cypress.config.tsSome tools (such as Cypress and Jest) support using TypeScript path aliases in the configuration file.
Potential workarounds:
- Rewrite the import in the configuration file to a relative import.
- Inject support with a module like
tsx:NODE_OPTIONS="--import tsx" knip - Or
tsconfig-paths:NODE_OPTIONS="--import tsconfig-paths/register.js" knip - Use Bun with knip-bun.
- See exceptions from config files for more potential workarounds.
Nx Daemon
Section titled “Nx Daemon”In Nx projects you might encounter this error:
NX Daemon process terminated and closed the connectionThe solution is to disable the Nx Daemon:
NX_DAEMON=false knipISC License © 2024 Lars Kappert