Skip to content

Commit 903d3a4

Browse files
committedMar 8, 2025·
Update docs
1 parent 15c4046 commit 903d3a4

File tree

2 files changed

+62
-55
lines changed

2 files changed

+62
-55
lines changed
 

‎packages/docs/src/content/docs/guides/handling-issues.mdx

+54-38
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,28 @@ This technically works, as `commitlint` is a transitive dependency of
320320

321321
## Unresolved imports
322322

323-
Knip may be unable to resolve an import specifier or dependency reference.
324-
325-
The most common causes for unresolved imports:
323+
Knip may ignore or be unable to resolve an import specifier or dependency
324+
references. The most common causes for unresolved imports:
326325

326+
- [Template strings][29]
327327
- [Extensionless imports][24]
328-
- [Unrecognized path aliases][29]
329-
- [External aliased imports][30]
328+
- [Unrecognized path aliases][30]
329+
- [External aliased imports][31]
330+
331+
### Template strings
332+
333+
Using template strings in dynamic imports might be ignored or not handled
334+
properly by Knip, resulting in false positives. Examples of dynamic import
335+
template strings:
336+
337+
```ts
338+
import(`./${value}.ts`);
339+
import(`@org/name/dist/${value}.js`);
340+
```
341+
342+
**Solution**: for internal source files, add the file(s) to the `entry`
343+
patterns. For external dependencies, add the dependency to the
344+
`ignoreDependencies` list.
330345

331346
### Extensionless imports
332347

@@ -348,11 +363,11 @@ similar to how standard ES Modules specifies file extensions are necessary.
348363

349364
### Unrecognized path aliases
350365

351-
Knip considers TSconfig path aliases and [paths configured in knip.json][31],
366+
Knip considers TSconfig path aliases and [paths configured in knip.json][32],
352367
but not those in e.g. Webpack or Vite configurations.
353368

354-
**Solution**: configure [paths][31] or try relative imports. Otherwise, use
355-
[`ignoreUnresolved`][32] as a last resort.
369+
**Solution**: configure [paths][32] or try relative imports. Otherwise, use
370+
[`ignoreUnresolved`][33] as a last resort.
356371

357372
### External aliased imports
358373

@@ -373,16 +388,16 @@ option][10] to tell Knip where to find the icon types:
373388
Where `[framework]` is the name of the framework you're using (see [available
374389
types][11]).
375390

376-
**Solution**: try [--include-libs][33] or configure [paths][31].
391+
**Solution**: try [--include-libs][34] or configure [paths][32].
377392

378393
## Unused exports
379394

380395
By default, Knip does not report unused exports of `entry` files.
381396

382397
The most common causes for unused exports include:
383398

384-
- [Namespace enumerations][34]
385-
- [External libraries][33]
399+
- [Namespace enumerations][35]
400+
- [External libraries][34]
386401

387402
Use the `--exports` flag to [filter][13] and focus only on issues related to
388403
exports:
@@ -391,7 +406,7 @@ exports:
391406
knip --exports
392407
```
393408

394-
Use [includeEntryExports][35] to report unused exports of entry files as well.
409+
Use [includeEntryExports][36] to report unused exports of entry files as well.
395410
This can be set per workspace.
396411

397412
### Namespace enumerations
@@ -403,7 +418,7 @@ are then **not** reported.
403418
**Solution**: if all exports on imported namespaces should be considered
404419
individually, include the `nsExports` issue type to disable the heuristic.
405420

406-
See [namepace imports][36] to see all related patterns.
421+
See [namepace imports][37] to see all related patterns.
407422

408423
### External libraries
409424

@@ -443,22 +458,22 @@ Knip does not include external type definitions by default so it won't see the
443458
export being referenced.
444459

445460
**Solution**: include the type definitions of external libraries with the
446-
[--include-libs][37] flag:
461+
[--include-libs][38] flag:
447462

448463
```shell
449464
knip --include-libs
450465
```
451466

452467
This comes at a performance and memory penalty, but should give better results
453-
if you need it. This flag is implied when [classMembers][38] are included (that
468+
if you need it. This flag is implied when [classMembers][39] are included (that
454469
feature comes with roughly the same performance penalty).
455470

456471
### Exclude exports from the report
457472

458473
To exclude false positives from the report, there are a few options:
459474

460-
- [Ignore exports used in file][39] for exports used internally.
461-
- Individual exports can be [tagged using JSDoc syntax][40].
475+
- [Ignore exports used in file][40] for exports used internally.
476+
- Individual exports can be [tagged using JSDoc syntax][41].
462477
- Have the export in an entry file:
463478
- Add the file to the `entry` file patterns array in the configuration.
464479
- Move the export(s) to an entry file.
@@ -468,7 +483,7 @@ To exclude false positives from the report, there are a few options:
468483
### Missing unused exports?
469484

470485
Did you expect certain exports in the report, but are they missing? They might
471-
be exported from an entry file. In that case, use [--include-entry-exports][35]
486+
be exported from an entry file. In that case, use [--include-entry-exports][36]
472487
to make Knip also report unused exports in entry files.
473488

474489
The exports of non-standard extensions like `.astro`, `.mdx`, `.vue` or
@@ -487,10 +502,10 @@ knip --include classMembers
487502
This option is also available in the Knip configuration file. Note that this
488503
feature comes at a cost: linting will take more time and more memory.
489504

490-
Individual class members can be [tagged using JSDoc syntax][40].
505+
Individual class members can be [tagged using JSDoc syntax][41].
491506

492507
Classes exported from entry files are ignored, and so are their members. Use
493-
[--include-entry-exports][35] to make Knip also report members of unused exports
508+
[--include-entry-exports][36] to make Knip also report members of unused exports
494509
in entry files.
495510

496511
### Enum members
@@ -502,18 +517,18 @@ Reporting such members can be disabled:
502517
knip --exclude enumMembers
503518
```
504519

505-
Individual enum members can be [tagged using JSDoc syntax][40].
520+
Individual enum members can be [tagged using JSDoc syntax][41].
506521

507522
Enums exported from entry files are ignored, and so are their members. Use
508-
[--include-entry-exports][35] to make Knip also report members of unused exports
523+
[--include-entry-exports][36] to make Knip also report members of unused exports
509524
in entry files.
510525

511526
## Feedback or false positives?
512527

513528
If you believe Knip incorrectly reports something as unused (i.e. there's a
514-
false positive), feel free to create a [minimal reproduction][41] and open an
529+
false positive), feel free to create a [minimal reproduction][42] and open an
515530
issue on GitHub. It'll make Knip better for everyone! Join the [Discord
516-
channel][42] to discuss any feedback or questions you may have.
531+
channel][43] to discuss any feedback or questions you may have.
517532

518533
[1]: #unused-files
519534
[2]: #unused-dependencies
@@ -544,17 +559,18 @@ channel][42] to discuss any feedback or questions you may have.
544559
[27]:
545560
https://github.com/webpro-nl/knip/blob/b70958a58ea255ee7a7831e404786da807ca93d7/packages/knip/src/constants.ts#L37-L139
546561
[28]: ../features/monorepos-and-workspaces.md#lint-a-single-workspace
547-
[29]: #unrecognized-path-aliases
548-
[30]: #external-aliased-imports
549-
[31]: ../reference/configuration.md#paths
550-
[32]: ../reference/configuration.md#ignoreunresolved
551-
[33]: #external-libraries
552-
[34]: #namespace-enumerations
553-
[35]: ../reference/configuration.md#includeentryexports
554-
[36]: ../guides/namespace-imports.md
555-
[37]: ../reference/cli#--include-libs
556-
[38]: #class-members
557-
[39]: ../reference/configuration.md#ignoreexportsusedinfile
558-
[40]: ../reference/jsdoc-tsdoc-tags.md
559-
[41]: ../guides/issue-reproduction
560-
[42]: https://discord.gg/r5uXTtbTpc
562+
[29]: #template-strings
563+
[30]: #unrecognized-path-aliases
564+
[31]: #external-aliased-imports
565+
[32]: ../reference/configuration.md#paths
566+
[33]: ../reference/configuration.md#ignoreunresolved
567+
[34]: #external-libraries
568+
[35]: #namespace-enumerations
569+
[36]: ../reference/configuration.md#includeentryexports
570+
[37]: ../guides/namespace-imports.md
571+
[38]: ../reference/cli#--include-libs
572+
[39]: #class-members
573+
[40]: ../reference/configuration.md#ignoreexportsusedinfile
574+
[41]: ../reference/jsdoc-tsdoc-tags.md
575+
[42]: ../guides/issue-reproduction
576+
[43]: https://discord.gg/r5uXTtbTpc

‎packages/docs/src/content/docs/reference/known-issues.md

+8-17
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
title: Known Issues
33
---
44

5-
This page contains a list of known issues you might run into when using Knip:
6-
7-
- [Exceptions from config files][1]
8-
- [False positives with external libs][2]
9-
- [DefinitelyTyped packages in dependencies][3]
10-
- [Extensionless imports][4]
5+
This page contains a list of known issues you might run into when using Knip.
116

127
## Exceptions from config files
138

@@ -18,7 +13,7 @@ environment variables set.
1813

1914
If it isn't clear what's throwing the exception, try another run with `--debug`
2015
to locate the cause of the issue with more details. Sometimes the issue is a
21-
missing environment variable. As a last resort, the [plugin can be disabled][5].
16+
missing environment variable. As a last resort, the [plugin can be disabled][1].
2217

2318
## Path aliases in config files
2419

@@ -41,8 +36,8 @@ the target values are not arrays).
4136
Potential workarounds:
4237

4338
- Rewrite the import in the configuration file to a relative import.
44-
- Use Bun with [knip-bun][6].
45-
- [Disable the plugin][5] (not recommended, try the other options first).
39+
- Use Bun with [knip-bun][2].
40+
- [Disable the plugin][1] (not recommended, try the other options first).
4641

4742
## Nx Daemon
4843

@@ -52,16 +47,12 @@ In Nx projects you might encounter this error:
5247
NX Daemon process terminated and closed the connection
5348
```
5449

55-
The solution is to [disable the Nx Daemon][7]:
50+
The solution is to [disable the Nx Daemon][3]:
5651

5752
```sh
5853
NX_DAEMON=false knip
5954
```
6055

61-
[1]: #exceptions-from-config-files
62-
[2]: #false-positives-with-external-libs
63-
[3]: #definitely-typed-packages-in-dependencies
64-
[4]: #extensionless-imports
65-
[5]: ./configuration.md#plugins
66-
[6]: ./cli.md#knip-bun
67-
[7]: https://nx.dev/concepts/nx-daemon#turning-it-off
56+
[1]: ./configuration.md#plugins
57+
[2]: ./cli.md#knip-bun
58+
[3]: https://nx.dev/concepts/nx-daemon#turning-it-off

0 commit comments

Comments
 (0)
Please sign in to comment.