facebook / facebook/docusaurus

Webpack stats error messages not printing problematic source filename

Đang mở
#9,023 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug domain: dx
Ngôn ngữ chính
TypeScript
Star
66.2k
Fork
10k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
52

Mô tả

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#issues).

### Prerequisites

- [X] I'm using the latest version of Docusaurus.
- [X] I have tried the `npm run clear` or `yarn clear` command.
- [X] I have tried `rm -rf node_modules yarn.lock package-lock.json` and re-installing packages.
- [X] I have tried creating a repro with https://new.docusaurus.io.
- [X] I have read the console error message carefully (if applicable).

### Description

The code to print console error messages is quite bad:

```tsx
import formatWebpackMessages from 'react-dev-utils/formatWebpackMessages';

export function formatStatsErrorMessage(
statsJson: ReturnType | undefined,
): string | undefined {
if (statsJson?.errors?.length) {
const {errors} = formatWebpackMessages(statsJson);
return errors
.map((str) => logger.red(str))
.join(`\n\n${logger.yellow('--------------------------')}\n\n`);
}
return undefined;
}
```

`'react-dev-utils/formatWebpackMessages'` does not print all the relevant info, notably the file path that on which the error happens, and this prevents users from solving their problems.

Example https://github.com/facebook/docusaurus/discussions/9022

### Reproducible demo

_No response_

### Steps to reproduce

- init new site
- add `src/thing.xyz`
- add `import './thing.xyz'` on `src/index.tsx`

Console error:

CleanShot 2023-05-30 at 16 39 41@2x

However, the Dev Server error overlay works better:

CleanShot 2023-05-30 at 16 40 05

### Expected behavior

We should print relevant information to the console. At least the file path.

This info is definitively available in the Webpack stats:

```js
const stats = {
errors: [
{
moduleIdentifier: '/Users/sebastienlorber/Desktop/website/src/pages/thing.xyz',
moduleName: './src/pages/thing.xyz',
loc: '1:0',
message: "Module parse failed: Unexpected character '🔥' (1:0)\n" +
'You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders\n' +
'> 🔥 bad file content'
}
],
errorsCount: 1,
warnings: [],
warningsCount: 0
}
```

### Actual behavior

Error message does not contain the problematic file path

### Your environment

- Docusaurus version used: v2.4.1 or v3 canary

### Self-service

- [X] I'd be willing to fix this bug myself.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.