@@ -320,13 +320,28 @@ This technically works, as `commitlint` is a transitive dependency of
320
320
321
321
## Unresolved imports
322
322
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:
326
325
326
+ - [ Template strings] [ 29 ]
327
327
- [ 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.
330
345
331
346
### Extensionless imports
332
347
@@ -348,11 +363,11 @@ similar to how standard ES Modules specifies file extensions are necessary.
348
363
349
364
### Unrecognized path aliases
350
365
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 ] ,
352
367
but not those in e.g. Webpack or Vite configurations.
353
368
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.
356
371
357
372
### External aliased imports
358
373
@@ -373,16 +388,16 @@ option][10] to tell Knip where to find the icon types:
373
388
Where ` [framework] ` is the name of the framework you're using (see [ available
374
389
types] [ 11 ] ).
375
390
376
- ** Solution** : try [ --include-libs] [ 33 ] or configure [ paths] [ 31 ] .
391
+ ** Solution** : try [ --include-libs] [ 34 ] or configure [ paths] [ 32 ] .
377
392
378
393
## Unused exports
379
394
380
395
By default, Knip does not report unused exports of ` entry ` files.
381
396
382
397
The most common causes for unused exports include:
383
398
384
- - [ Namespace enumerations] [ 34 ]
385
- - [ External libraries] [ 33 ]
399
+ - [ Namespace enumerations] [ 35 ]
400
+ - [ External libraries] [ 34 ]
386
401
387
402
Use the ` --exports ` flag to [ filter] [ 13 ] and focus only on issues related to
388
403
exports:
@@ -391,7 +406,7 @@ exports:
391
406
knip --exports
392
407
```
393
408
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.
395
410
This can be set per workspace.
396
411
397
412
### Namespace enumerations
@@ -403,7 +418,7 @@ are then **not** reported.
403
418
** Solution** : if all exports on imported namespaces should be considered
404
419
individually, include the ` nsExports ` issue type to disable the heuristic.
405
420
406
- See [ namepace imports] [ 36 ] to see all related patterns.
421
+ See [ namepace imports] [ 37 ] to see all related patterns.
407
422
408
423
### External libraries
409
424
@@ -443,22 +458,22 @@ Knip does not include external type definitions by default so it won't see the
443
458
export being referenced .
444
459
445
460
** Solution** : include the type definitions of external libraries with the
446
- [ --include-libs] [ 37 ] flag:
461
+ [ --include-libs] [ 38 ] flag:
447
462
448
463
``` shell
449
464
knip --include-libs
450
465
```
451
466
452
467
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
454
469
feature comes with roughly the same performance penalty).
455
470
456
471
### Exclude exports from the report
457
472
458
473
To exclude false positives from the report, there are a few options:
459
474
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 ] .
462
477
- Have the export in an entry file:
463
478
- Add the file to the ` entry ` file patterns array in the configuration.
464
479
- Move the export(s) to an entry file.
@@ -468,7 +483,7 @@ To exclude false positives from the report, there are a few options:
468
483
### Missing unused exports?
469
484
470
485
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 ]
472
487
to make Knip also report unused exports in entry files.
473
488
474
489
The exports of non-standard extensions like ` .astro ` , ` .mdx ` , ` .vue ` or
@@ -487,10 +502,10 @@ knip --include classMembers
487
502
This option is also available in the Knip configuration file. Note that this
488
503
feature comes at a cost: linting will take more time and more memory.
489
504
490
- Individual class members can be [ tagged using JSDoc syntax] [ 40 ] .
505
+ Individual class members can be [ tagged using JSDoc syntax] [ 41 ] .
491
506
492
507
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
494
509
in entry files.
495
510
496
511
### Enum members
@@ -502,18 +517,18 @@ Reporting such members can be disabled:
502
517
knip --exclude enumMembers
503
518
```
504
519
505
- Individual enum members can be [ tagged using JSDoc syntax] [ 40 ] .
520
+ Individual enum members can be [ tagged using JSDoc syntax] [ 41 ] .
506
521
507
522
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
509
524
in entry files.
510
525
511
526
## Feedback or false positives?
512
527
513
528
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
515
530
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.
517
532
518
533
[ 1 ] : #unused-files
519
534
[ 2 ] : #unused-dependencies
@@ -544,17 +559,18 @@ channel][42] to discuss any feedback or questions you may have.
544
559
[ 27] :
545
560
https://github.com/webpro-nl/knip/blob/b70958a58ea255ee7a7831e404786da807ca93d7/packages/knip/src/constants.ts#L37-L139
546
561
[ 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
0 commit comments