Webpack 5: incorrect compilation error text output starting with "undefined undefined"
UncleJart opened this issue · 3 comments
- Operating System: Windows 10 22H2
- Node Version: 18.19.0
- NPM Version: 10.2.3
- webpack Version: 5.89.0
- @babel/core Version: 7.22.9
- @babel/preset-env Version: 7.22.9
- eslint Version: 8.48.0
- eslint-webpack-plugin Version: 4.0.1
- typescript Version: 4.5.4
- fork-ts-checker-webpack-plugin Version: 9.0.2
- webpack-hot-middleware Version: 2.26.0
Expected Behavior
When error occurred during module compilation in case webpack stats error object moduleName
and (or) loc
fields are not present they should have fallback to empty string or should not be added to error string output.
Actual Behavior
When error occurred during module compilation in case webpack error moduleName
and (or) loc
fields are not present their actual value undefined
is converted to string, added to error string output and send from middleware to client module.
How Do We Reproduce?
Reproduced with any code which compiles with error.
The problem is in function formatErrors
which takes error(s) from webpack stats object and generates a string from some of its fields.
...
// Convert webpack@5 error info into a backwards-compatible flat string
return errors.map(function (error) {
return error.moduleName + ' ' + error.loc + '\n' + error.message;
});
...
In webpack 5 fields moduleName
and loc
are optional, so they could be absent. In this case we receive value for these fields converted to string undefined
in formatted error output.
declare interface KnownStatsError {
message: string;
chunkName?: string;
chunkEntry?: boolean;
chunkInitial?: boolean;
file?: string;
moduleIdentifier?: string;
moduleName?: string;
loc?: string;
chunkId?: string | number;
moduleId?: string | number;
moduleTrace?: StatsModuleTraceItem[];
details?: any;
stack?: string;
}
Hello, do you want to send a PR with fix?
Hello, created pull request. Added fallbacks to empty strings to keep same output behavior as was for webpack 4.
Fixed by #447, thank you