facebook / facebook/docusaurus

Error messages set to `vfile` by Remark plugins are not reported.

Abierto
#9,953 1 comentario 0 reacciones 0 asignados Ver en GitHub
bug domain: markdown
Lenguaje dominante
TypeScript
Estrellas
66.2k
Forks
10k
Merge medio
1 d 3 h
PR fusionados (30 d)
52

Descripción

### 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

Remark plugins need to issue warnings and create errors when processing mdx files. They can do so using the [vfile.message](https://github.com/vfile/vfile#vfilemessagereason-options) mechanism already.

The messages can be reported with the [vfile-reporter](https://github.com/vfile/vfile-reporter) utility. The `reporter` presents the messages in a convenient way, grouping messages by file and linking each error to the reported line and column number in the mdx document.

However, **when Docusaurus applies a Remark plugin to a mdx document, it doesn't report the warnings and errors**.

I can kind of get around it by writing a new Remark plugin, and putting it at the end of the pipeline:

```js
import { reporter } from "vfile-reporter";
export default function reporter() {
return (_, vfile) => {
console.error(reporter(vfile));
};
}
```

but this is not very neat as the plugins are executed multiple times during `docusaurus start` and it relentlessly spams the terminal. To experience this, uncomment the `[require("./plugins/plugin-reporting.js"), {}],` line (line 51, docusaurus.config.js) in the bug repro.

### Reproducible demo

https://codesandbox.io/p/devbox/priceless-meadow-dq4n4h?file=%2Fplugins%2Fplugin-erroring.js%3A3%2C59

### Steps to reproduce

In any remark plugin, add a `vfile.message("message")` line. It should show up but doesn't.

Check the codesandbox repro for demo.

### Expected behavior

I expect the messages that the Remark plugins set on vfiles are reported by Docusaurus either by default or as a simple config toggle.

### Actual behavior

The messages are never shown.

### Your environment

- Public source code: https://codesandbox.io/p/devbox/priceless-meadow-dq4n4h?file=%2Fplugins%2Fplugin-erroring.js%3A3%2C59
- Public site URL:
- Docusaurus version used: 3.1.1
- Environment name and version (e.g. Chrome 89, Node.js 16.4):
- Operating system and version (e.g. Ubuntu 20.04.2 LTS):

### Self-service

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.