在WSL中安装Mermaid CLI失败时可参考以下详细解决方案1. Node.js环境问题前置条件确保已安装Node.js建议v16检查版本运行node --version验证安装失败时使用以下命令安装Node.js# 使用nvm安装Node.js推荐curl-o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh|bashsource~/.bashrc nvminstall--ltsnvm use--lts清理npm缓存npm cache clean --force永久设置镜像npm config set registry https://registry.npmmirror.com2. Puppeteer依赖问题核心原因Mermaid CLI依赖Puppeteer而Puppeteer默认会下载Chromium可能因权限或路径问题失败解决方案跳过Chromium下载设置环境变量export PUPPETEER_SKIP_DOWNLOADtrueUbuntu系统直接安装Chromium推荐# 安装Chromium浏览器sudoapt-getupdatesudoapt-getinstall-ychromium-browser# 配置Puppeteer使用系统ChromiumexportPUPPETEER_EXECUTABLE_PATH$(whichchromium-browser)# 永久生效添加到~/.bashrcechoexport PUPPETEER_EXECUTABLE_PATH$(which chromium-browser)~/.bashrcsource~/.bashrc备选方案手动安装Chrome# 下载并安装Chromewgethttps://dl.google.com/linux/direct/google-chrome-stable_current_amd64.debsudoaptinstall./google-chrome-stable_current_amd64.debrmgoogle-chrome-stable_current_amd64.deb# 设置环境变量exportPUPPETEER_EXECUTABLE_PATH/usr/bin/google-chromeechoexport PUPPETEER_EXECUTABLE_PATH/usr/bin/google-chrome~/.bashrcsource~/.bashrc3. 网络问题国内用户推荐安装时强制使用国内镜像npminstall-gmermaid-js/mermaid-cli--verbose--registryhttps://registry.npmmirror.com证书过期若遇CERT_HAS_EXPIRED错误切换镜像源npmconfigsetregistry https://registry.npmmirror.com4. 权限问题提升权限安装在安装命令前添加sudo避免全局安装路径无写入权限检查权限确保用户对~/.cache/puppeteer有读写权限5. 其他问题检查日志安装失败时查看详细日志定位问题cat ~/.npm/_logs/*.log使用Docker若环境配置复杂可用Docker容器替代