Skip to content

Commit

Permalink
fix(overlay): fallback to moduleName if moduleIdentifier parse failed (
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Apr 28, 2024
1 parent cbb021f commit b68b680
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/core/src/client/formatStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ function isLikelyASyntaxError(message: string) {
}

function resolveFileName(stats: webpack.StatsError) {
const regex = /(?:\!|^)([^!]+)$/;

// Get the real source file path with stats.moduleIdentifier.
// e.g. moduleIdentifier is builtin:react-refresh-loader!/Users/x/src/App.jsx"
let fileName = stats.moduleIdentifier?.match(regex)?.at(-1) ?? '';

// add default column add lines
if (fileName) fileName = `File: ${fileName}:1:1\n`;

return fileName;
// e.g. moduleIdentifier is "builtin:react-refresh-loader!/Users/x/src/App.jsx"
const regex = /(?:\!|^)([^!]+)$/;
const fileName = stats.moduleIdentifier?.match(regex)?.at(-1) ?? '';
return fileName
? // add default column add lines for linking
`File: ${fileName}:1:1\n`
: // fallback to moduleName if moduleIdentifier parse failed
`File: ${stats.moduleName}\n`;
}

// Cleans up webpack error messages.
Expand Down

0 comments on commit b68b680

Please sign in to comment.