circular-dependency-plugin
circular-dependency-plugin copied to clipboard
Typescript Type Dependencies Not Found
Steps to Reproduce:
- Have a webpack 4 project with typescript.
- Create file
TableRenderer.ts:
import { Table } from './Table';
const renderTable = (table: Table) => console.log(JSON.stringify(table));
- Create file
Table.ts:
import * as TableRenderer from './TableRenderer';
export const renderMethods = TableRenderer;
- Run webpack with
circular-dependency-pluginenabled.
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.
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.
Same issue, this plugin needs better typescript support. I'm everyday watching 100+ warnings about circular dependency. (when they are not circular)