facebook / facebook/docusaurus

Build fails when blog is a subdirectory of the docs

Open
#11,607 3 comments 0 reactions 0 assignees View on GitHub
bug
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#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

For corporate reasons™ I need to store the blog posts in a subdirectory of the docs (actually, in my specific case, docs path = '..', and blog path = '../release_notes', but I can reproduce the bug without '..' in the paths for a more standard installation).

The build fails with a kinda weird error.

### Reproducible demo

_No response_

### Steps to reproduce

```
npx create-docusaurus@latest my-website classic --typescript
cd my-website
mv blog docs
```

Then patch `docusaurus.config.ts`:

* Add the line `exclude: ['blog'],` in the docs preset
* Add the line `path: 'docs/blog',` in the blog preset

Then `yarn build`.

### Expected behavior

A perfectly indistinguishable build from the example

### Actual behavior

A bunch of those errors:

```
lient bundle compiled with errors therefore further build is impossible.
Error: MDX compilation failed for file "/home/felix/tmp/my-website/docs/blog/2019-05-28-first-blog-post.md"
Cause: Unexpected `FunctionDeclaration` in code: only import/exports are supported
Details:
{
"column": 1,
"file": "",
"message": "Unexpected `FunctionDeclaration` in code: only import/exports are supported",
"line": 24,
"name": "24:1-33:2",
"place": {
"start": {
"line": 24,
"column": 1,
"offset": 564
},
"end": {
"line": 33,
"column": 2,
"offset": 778
}
},
"reason": "Unexpected `FunctionDeclaration` in code: only import/exports are supported",
"ruleId": "non-esm",
"source": "micromark-extension-mdxjs-esm",
"url": "https://github.com/micromark/micromark-extension-mdxjs-esm#unexpected-type-in-code-only-importexports-are-supported"
}

--------------------------
```

### Your environment

- Docusaurus version used: 3.9.2
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Nodejs 22.21.0
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): Ubuntu 24.04

### Self-service

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.