circular-dependency-plugin icon indicating copy to clipboard operation
circular-dependency-plugin copied to clipboard

Typescript Type Dependencies Not Found

Open abirmingham opened this issue 6 years ago • 2 comments

Steps to Reproduce:

  1. Have a webpack 4 project with typescript.
  2. Create file TableRenderer.ts:
import { Table } from './Table';

const renderTable = (table: Table) => console.log(JSON.stringify(table));
  1. Create file Table.ts:
import * as TableRenderer from './TableRenderer';

export const renderMethods = TableRenderer;
  1. Run webpack with circular-dependency-plugin enabled.

Expected Result: Circular dependency of TableRenderer -> Table -> TableRenderer. Actual Result: No circular dependency found.

Due to type erasure, and the circular-dependency-plugin's usage of compilation.hooks.optimizeModules, it looks like this isn't easily solvable. Perhaps there is a hook earlier in the webpack life cycle that provides dependencies prior to type erasure? I'm not sure.

abirmingham avatar Sep 19 '19 19:09 abirmingham

Note that pahen/madge appears to avoid the issue of type erasure by parsing/checking the AST directly rather than relying on generated webpack assets (which has pros and cons). I mention it here in case someone is investigating tools to circumvent this issue.

abirmingham avatar Sep 19 '19 20:09 abirmingham

Same issue, this plugin needs better typescript support. I'm everyday watching 100+ warnings about circular dependency. (when they are not circular)

sionzee avatar Jun 11 '20 20:06 sionzee