Registry / devops / circular-dependency-plugin

circular-dependency-plugin

JSON →
library5.2.2jsnpmunverified

A webpack plugin that detects modules with circular dependencies during the bundling process. Current stable version is 5.2.2, released in 2021, with infrequent updates due to stability. It integrates deeply with webpack's compilation lifecycle, offering hooks like onStart, onDetected, and onEnd for custom handling, and supports excluding/including files via RegExp. Unlike static analysis tools, it works on webpack's resolved module graph. Requires webpack >=4.0.1 as a peer dependency.

npm install circular-dependency-plugin
INSTALL
IMPORT
SIG · CIRCULAR-DEPENDENC
C
circular-dependency-plugin
devopsjavascriptv5.2.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CircularDependencyPlugin
const CircularDependencyPlugin = require('circular-dependency-plugin')
import CircularDependencyPlugin from 'circular-dependency-plugin'
This plugin is designed for webpack config files which typically use CommonJS. ESM import may work but is not officially supported.
CircularDependencyPlugin
new CircularDependencyPlugin({...})
CircularDependencyPlugin({...})
Must be instantiated with `new` as it is a class constructor.
Plugin Options
{ exclude: /node_modules/, failOnError: true }
{ exclude: 'node_modules', failOnError: 'true' }
Both exclude/include accept RegExp, not strings. failOnError expects boolean, not string.

Webpack configuration integrating CircularDependencyPlugin to detect and warn on circular imports.

// webpack.config.js const path = require('path'); const CircularDependencyPlugin = require('circular-dependency-plugin'); module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js' }, plugins: [ new CircularDependencyPlugin({ exclude: /node_modules/, include: /dir/, failOnError: false, allowAsyncCycles: false, cwd: process.cwd(), onDetected({ module: webpackModuleRecord, paths, compilation }) { compilation.warnings.push(new Error(paths.join(' -> '))); } }) ] };
Debug
Known issues
gotchaPlugin only works on modules that webpack resolves; it does not detect cycles from dynamic imports unless allowAsyncCycles is set to false.
fix
Set allowAsyncCycles: false to detect cycles involving async imports (default behavior).
affects: >=5.0.0
breakingVersion 5 dropped support for webpack 3.x and below. Only webpack >=4.0.1 is supported.
fix
If using webpack 3.x, use circular-dependency-plugin@4 or lower.
affects: >=5.0.0
deprecatedThe `cwd` option is deprecated in favor of using module context directly.
fix
Remove the `cwd` option; webpack's internal module resolution handles it.
affects: >=5.0.0
gotchaSetting `failOnError: true` will cause webpack to emit errors instead of warnings, potentially breaking the build.
fix
Use `failOnError: false` to emit warnings only (default).
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: CircularDependencyPlugin is not a constructor
Importing as default export instead of the correct import pattern.
fix
Use `const CircularDependencyPlugin = require('circular-dependency-plugin');` with `new`.
Circular dependency detected: src/a.js -> src/b.js -> src/a.js
Actual circular import in your codebase.
fix
Refactor code to break the cycle or add the cycle to an exclusion list.
Plugin circular-dependency-plugin is not compatible with webpack 3. Please upgrade to webpack 4 or higher.
Using version 5 of the plugin with webpack 3.
fix
Downgrade to circular-dependency-plugin@4 or upgrade webpack to >=4.0.1.
Upgrade
Version history
5.2.2latest on npm
Audit
Dependencies
webpackrequiredPeer dependency required to hook into webpack's compilation process
Agent activity
2 hits · last 30 days
node
2
Resources