Known Issues
This page contains a list of known issues you might run into when using Knip:
- Exceptions from config files
- False positives with external libs
- DefinitelyTyped packages in dependencies
- Extensionless imports
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
. Knip may
load such files differently, in a different environment, or without certain
environment variables set.
If it isn’t clear what’s throwing the exception, try another run with --debug
to locate the cause of the issue with more details.
Path aliases in config files
Loading the configuration file (e.g. cypress.config.ts
) for one of Knip’s
plugins may give an error:
Some tools (such as Cypress and Jest) support using TypeScript path aliases in
the configuration file. Jiti does support aliases, but in a different format
compared to tsconfig.json#compilerOptions.paths
and knip.json#paths
(e.g.
the target values are not arrays).
Potential workarounds:
- Rewrite the import in the configuration file to a relative import.
- Use Bun with knip-bun.
- Disable the plugin (not recommended, try the other options first).
False positives with external libs
Knip may report false positives when exports are consumed by external libraries.
Please see external libs.
dependencies
Definitely Typed packages in Knip is strict in the divide between dependencies
and devDependencies
. Some
packages are published with one or more DT packages bundled (i.e. listed in
dependencies
). Knip does not make exceptions for such type packages
(@types/*
) and expects them in devDependencies
.
Extensionless imports
Knip does not support extensionless imports for some non-standard extensions,
such as for .svg
files. Bundlers like Webpack may support this, but Knip does
not. Examples:
The recommendation is to always add the extension when importing such files, similar to how standard ES Modules work.
ISC License © 2024 Lars Kappert