Bug / UX Enhancement - Circular Dependency Error Messages#20393
Bug / UX Enhancement - Circular Dependency Error Messages#20393asadjan4611 wants to merge 6 commits intowebpack:mainfrom
Conversation
|
| [ | ||
| /There is a circular build dependency/, | ||
| /Circular dependency detected/, | ||
| /Circular dependency chain:/, |
There was a problem hiding this comment.
I don't see you real test here with improve message
| if (errorMessage.includes("Circular dependency detected")) { | ||
| expect(errorMessage).toMatch(/Circular dependency chain:/); | ||
| expect(errorMessage).toMatch(/To fix this circular dependency:/); | ||
| } |
There was a problem hiding this comment.
Still not see test a good message
|
okay thanks for quick review @alexander-akait |
|
Hey @alexander-akait, |
|
@alexander-akait sorry for again reminders ! |
- Add comprehensive full message pattern verification - Verify complete error structure including dependency chain - Test all suggestions are present in error messages - Ensure tests verify full message format as requested by maintainer Fixes maintainer feedback on test coverage
|
@alexander-akait Please review it again.i have fix all the issue's |
| /\s*↻ .*moduleA\.js/, | ||
| /\s*→\s+.*moduleA\.js(\s+\(line\s+\d+\))?/, | ||
| /\s*→\s+.*moduleB\.js(\s+\(line\s+\d+\))?/, | ||
| /\s*↻\s+.*moduleA\.js(\s+\(line\s+\d+\))?/, |
There was a problem hiding this comment.
Please use statsCases to test errors/warnings output
- Add statsCase test to verify formatted error output in console - Tests the enhanced circular dependency error message in stats output - Follows maintainer feedback to use statsCases for error/warning testing
| /- Consider refactoring the module structure to remove the dependency cycle/ | ||
| ] | ||
| ]; | ||
|
|
There was a problem hiding this comment.
Move all test cases in statsCases and handle all your branches in your code, your code is not under coverage metrics
|
@alexander-akait I also fixed it please review it |
…mprehensive coverage - Remove configCase test (moved to statsCases as requested) - Add multiple test scenarios in statsCases (2-module and 3-module cycles) - Ensure all code branches are covered: * 2-module cycle (tests specific suggestion path) * 3+ module cycle (tests generic suggestion path) * Both test main path resolution (path.length > 1) - Improve code coverage metrics as requested by maintainer
| } | ||
|
|
||
| return chain; | ||
| } |
There was a problem hiding this comment.
Please simplify it, it is AI generated code and most of lines are not covered, also add jsdocs, run locally yarn lint:code
There was a problem hiding this comment.
Simplify doesn't mean to move everything to methods, it means simplif - remove unused lines and refactror code, do you understand what are you doing and how to do it?
- Extract helper methods _getModulePath and _getLocationInfo - Simplify path building logic (remove complex DFS) - Add comprehensive JSDoc documentation - Reduce code complexity for better test coverage - Fix indentation issues in BuildCycleError
Problem
When webpack encounters a circular dependency, the error message is too generic and doesn't provide enough information to help developers debug the issue. The current error only states "There is a circular build dependency" without showing:
This makes debugging circular dependencies extremely difficult, especially in large codebases with hundreds of modules.
Solution
Enhanced the
BuildCycleErrorclass to provide detailed dependency chain information when circular dependencies are detected. The implementation includes:RequestShortenerwhen availableformatLocationutilityChanges Made
1.
lib/errors/BuildCycleError.jscycleChain,moduleGraph, andrequestShortenerparametersgetFormattedMessage()method to format the dependency chain with file paths and line numbers2.
lib/Compilation.js_buildCycleChain()method to accurately trace the full dependency cycle using DFS algorithm3. Test Files
test/cases/errors/load-module-cycle/index.jsto verify enhanced error message formattest/configCases/errors/circular-dependency-enhanced/for comprehensive coverageExample Output
Before:
After:
Benefits
Backward Compatibility
The implementation is fully backward compatible. If
cycleChainis not provided, the error behaves as before. Existing error handling remains unchanged with no breaking changes to the API.Testing
Summary
This PR enhances circular dependency error messages to show the full dependency chain, file paths with line numbers, and actionable suggestions for fixing the issue.
What kind of change does this PR introduce?
Did you add tests for your changes?
Does this PR introduce a breaking change?
The implementation is fully backward compatible. If
cycleChainis not provided, the error behaves as before.If relevant, what needs to be documented once your changes are merged or what have you already documented?