aackerman / circular-dependency-plugin

Detect circular dependencies in modules compiled with Webpack
https://www.npmjs.com/package/circular-dependency-plugin
ISC License
914 stars 46 forks source link

webpack@5.11.1 support with circular dependency #64

Open haripriyaaganesan opened 3 years ago

haripriyaaganesan commented 3 years ago

I'm migrating my project from webpack@4.41.2 -> webpack@5.11.1. I'm running into circular dependency issue.

Error: Circular dependency detected: assets/images/card_auth_illustration.png -> assets/images/card_auth_illustration.png

ERROR in Error: Child compilation failed: Circular dependency detected: src/index.html -> src/index.html Error: Circular dependency detected: src/index.html -> src/index.html

webpack.commom.js

const CircularDependencyPlugin = require('circular-dependency-plugin'); plugins: [ new CircularDependencyPlugin({ exclude: /a.js|node_modules/, include: /src/, failOnError: true, }) ]

aackerman commented 3 years ago

@haripriyaaganesan which version of the plugin were you using? As of 5.2.2 the intent is to never list a self reference circular dependency.

Doodidan commented 3 years ago

I catch this bug on 5.0.2. Upgrading to 5.2.2 helps me, everything is ok now.

magicznyleszek commented 2 years ago

I'm upgrading webpack from v4 to v5, and and am currently using 5.72.0 with circular-dependency-plugin@5.2.2 and I get a long list of self referencing files. As a temporary solution I did this:

onDetected({paths, compilation}) {
  if (paths.length === 2 && paths[0] === paths[1]) {
    // SKIP IT
  } else {
    compilation.warnings.push(new Error(paths.join(' -> ')));
  }
},

(I use warnings instead of errors)

Turned out I was running it with 5.2.0 as I forgot to npm install after switching branches. Sorry for trouble!