Rollup "Circular dependency" warning failing CI
Rollup detected an import cycle between modules. The warning is informational, but in a cycle an export can be undefined at evaluation time, and pipelines that turn warnings into errors fail the build on it.
What this error means
The build logs "(!) Circular dependency" followed by the chain of files, for example "src/a.js -> src/b.js -> src/a.js", and fails if warnings are errors.
(!) Circular dependency
src/a.js -> src/b.js -> src/a.jsCommon causes
Two modules import each other
A direct or indirect cycle means one module is evaluated before the other finishes, so a referenced export may be undefined at that point.
Barrel files re-exporting in a loop
An index.js that re-exports modules which import back from it creates cycles that Rollup reports.
How to fix it
Break the cycle
- Read the cycle chain Rollup prints.
- Move the shared code into a third module both can import.
- Re-run so the warning clears.
Acknowledge known-safe cycles in onwarn
If a cycle is intentional and safe, filter just that warning code so it does not fail the build.
// rollup.config.js
export default {
onwarn(warning, warn) {
if (warning.code === 'CIRCULAR_DEPENDENCY') return;
warn(warning);
},
};How to prevent it
- Avoid mutual imports; extract shared code to its own module.
- Keep barrel files from re-exporting modules that import back.
- Only suppress circular warnings you have verified are safe.