我使用的 vitepress 安装 markdown-it-mermaid报错 Cannot read properties of undefined (reading 'document') at d3.js:8:26
时间: 2024-02-12 20:30:42 浏览: 206
这个错误通常是由于在服务器端(如使用 Node.js 或 Vitepress)执行 Mermaid 时,由于缺少浏览器 API 导致的。您可以尝试使用 mermaid.cli 渲染 Mermaid 图表,而不是在浏览器中渲染。以下是使用 mermaid.cli 的步骤:
1. 安装 mermaid.cli:
```bash
npm install -g mermaid.cli
```
2. 在 Markdown 文件中,使用以下代码块语法来代替 Mermaid 代码块:
````markdown
```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```
````
3. 在构建或预览 Vitepress 网站之前,在命令行中运行以下命令:
```bash
mermaid -p node_modules/mermaid/dist/ -w 1024 -H 768 -i markdown < your_markdown_file.md > your_markdown_file_rendered.md
```
此命令将使用 mermaid.cli 将 Mermaid 代码块转换为 SVG,并将其输出到名为 `your_markdown_file_rendered.md` 的新文件中。
4. 在 Vitepress 中,在您的 Markdown 文件中,将原始 Mermaid 代码块替换为新生成的 Markdown 文件中的 SVG 代码块。
请注意,这种方法不支持动态更新 Mermaid 图表。如果您需要动态图表,您将需要使用服务器端渲染(SSR)或启用客户端渲染(CSR)。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)