Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(overlay): fallback to moduleName if moduleIdentifier parse failed #2225

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading