facebook/Docusaurus
View on GitHubModule with Top-level await transformed incorrectly during server build
Open
#7238 opened on Apr 25, 2022
bugdifficulty: advancedexternalhelp wanted
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- 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:
---
title: Markdown page example
---
export const test = await Promise.resolve('hello')
<div>{test}</div>
Reproducible demo
https://stackblitz.com/edit/github-7mt6ad?file=src/pages/test.mdx
Steps to reproduce
- Enable top-level await support in webpack by setting
experiments.topLevelAwaittotrueusing configureWebpack (see plugins at docusaurus.config.js ) - Try using top-level await during
docusaurus run, things work fine. - 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.