Adding mermaid plugin breaks the document project when Yarn v4 is used and the NPM is disabled. #10645
Open
6 of 7 tasks
Labels
bug
An error in the Docusaurus core causing instability or issues with its execution
status: needs triage
This issue has not been triaged by maintainers
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.Description
Problem Description
The whole document project will break down when the following conditions are met:
@docusaurus/theme-mermaid
is used indocusaurus.config.ts
..yarnrc
, i.e. all packages are linked by Yarn.I need to emphasize that this issue only happens if the mermaid plugin is used. If it is not used, there will be no problems.
Background
Yarn v4 provides a very amazing feature. All packages are managed as zipped files in the cache. There will be no need to create another copy of packages like what we have in
node_modules
folder, which saves a lot of space.Unfortunately, I spot that Yarn 4 seems to fail to correctly manage the packages compared to
npm
. If the pacakges are linked bynpm
, mermaid can work correctly. However, if the packages are linked by the Yarn 4, the same codes will not work. I am not sure whether the problem is caused by Yarn or the design of the mermaid plugin. If the mermaid plugin is the one that can be fixed, it will be good news to me.Reproducible demo
https://codesandbox.io/p/devbox/objective-framework-rdwmd9
Steps to reproduce
Delete the
node_modules
folder byrm -rf node_modules
. If.yarnrc
exists, also delete it.In the
package.json
, addpackageManager
,@docusaurus/plugin-content-docs
, and@docusaurus/theme-mermaid
:Turn on the Yarn v4 and install dependencies:
Add mermaid testing codes in the
docs/intro.md
Run the project by
yarn start
.Expected behavior
The probject works well if using
npm install
andnpm run start
. I think when usingyarn install
andyarn start
, its behavior should be the same.Actual behavior
Errors
The first error occurs once the index page is loaded. It will happen as long as the mermaid plugin is configured, even if we do not add any mermaid code blocks.
The second error happens when accessing a page having a mermaid block. Certainly, the mermaid block cannot be rendered in this case.
How to make the error disappear
The following part shows my inspections on this issue. These solutions do not actually fix this issue but can be viewed as a compromission for somehow. I am still looking forward to seeing a real solution. But I do not have an idea to fix it by myself.
Doing any one of the following solutions will make the error disappeared.
Solution 1: Do not use mermaid
If the mermaid plugin is removed from
docusaurus.config.ts
, the project will work fine. Actually, I have used Yarn 4 and Docusaurus 3 to build several websites without any issues.Solution 2: Make the packages linked by NPM
If the NPM linker is turned on by adding the following line to
.yarnrc
, the mermaid plugin will work correctly and the errors will disappear. However, this option brings the largenode_modules
folder back which is not an ideal solution to me.Extra comments
I believe that this issue should exist for long. Maybe it firstly occurred when Yarn v4 was available. I spot that a different Docusaurus project met the same issue one year ago. The maintainers of that project solved it by removing the mermaid plugin. See
https://gitlab.com/hoppr/hoppr-docs/-/issues/41
Your environment
3.6.0
python:3.12-slim
Self-service
The text was updated successfully, but these errors were encountered: