facebook / facebook/docusaurus
Module with Top-level await transformed incorrectly during server build
- Dominant language
- TypeScript
- Stars
- 66.2k
- Forks
- 10k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 52
Description
### 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')
```
### 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.
Contributor guide
Assessment
This issue has not been assessed yet.