facebook / facebook/docusaurus

Module with Top-level await transformed incorrectly during server build

Abierto
#7,238 5 comentarios 0 reacciones 0 asignados Ver en GitHub
bug difficulty: advanced external
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#reporting-new-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

Hi, I have enabled top-level await support in webpack config, and things work fine during `docusaurus run`, but fails during `docusaurus build`

This is my mdx content:
```mdx
---
title: Markdown page example
---
export const test = await Promise.resolve('hello')

{test}

```

### Reproducible demo

https://stackblitz.com/edit/github-7mt6ad?file=src/pages/test.mdx

### Steps to reproduce

1. Enable top-level await support in webpack by setting `experiments.topLevelAwait` to `true` using [configureWebpack](https://docusaurus.io/docs/api/plugin-methods/lifecycle-apis#configureWebpack) (see plugins at [docusaurus.config.js](https://stackblitz.com/edit/github-7mt6ad?file=docusaurus.config.js) )
2. Try using top-level await during `docusaurus run`, things work fine.
3. It fails during `docusaurus build`

### Expected behavior

top-level await should also work during build process

### Actual behavior

top-level await doesn't work during build process

```

[INFO] [en] Creating an optimized production build...

✔ Client

✖ Server
Compiled with some errors in 18.35s

[ERROR] Docusaurus server-side rendering could not render static page with path /test.

TypeError: Cannot read properties of undefined (reading 'title')
[ERROR] Unable to build website for locale en.
[ERROR] Error: Failed to compile with errors.

```

### Your environment

- Docusaurus version used: 2.0.0-beta.18
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): windows 10

### Self-service

- [ ] 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.