Re-export cycles
What a re-export-cycle finding of fallow dead-code means, why it matters and how to fix it.
What it reports
Two or more barrel files re-export from each other in a loop.
Architecture explains how fallow finds it.
Why it matters
A barrel file re-exports from another barrel that ultimately re-exports back. When this happens, imports from any file in the loop may silently come up empty, because the re-export chain has no terminating module to resolve names against. To fix this: open any one file in the loop and remove the export * from (or export { ... } from) statement that points back into the cycle. Any single removal will break the cycle and restore working re-exports. A self-loop (a single barrel re-exporting from itself, often a rename leftover) is reported under the same rule with kind self-loop.
Example
src/ui/index.ts has export * from './forms', and src/ui/forms/index.ts has export * from '..', so the two barrels re-export from each other.
Fix
Remove one export ... from statement in the loop that points back into the cycle. For a self-loop, remove the statement with which the file re-exports itself.
Facts
| Fact | Value |
|---|---|
| Issue type | re-export-cycle |
| Rule id in SARIF output | fallow/re-export-cycle |
| Command | fallow dead-code |
| Default severity | warn |
Config key in rules | re-export-cycle |
| Filter option | --re-export-cycles |
| Suppression comment | // fallow-ignore-file re-export-cycle |
Fixable with fallow fix | No |
| Opt-in | No |
When to keep the code
- An old project with hand-written barrel files can have loops that no code uses. Keep the rule at
warnuntil you remove them, then set it toerror.
Notes
The finding belongs to a group of files, not to one line. Suppress it with // fallow-ignore-file re-export-cycle in one file of the loop. A rule in overrides has no effect on this issue type.