facebook / facebook/docusaurus

Module with Top-level await transformed incorrectly during server build

Aperta
#7,238 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug difficulty: advanced external
Lingua principale
TypeScript
Stelle
66.2k
Fork
10k
Merge medio
1g 3h
PR unite (30g)
52

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.