You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vuepress构建后Markdown文件字符间出现�乱码问题咨询

Fixing VuePress Build: Strange � Characters Between Every Character in Output HTML

Hey there, let’s tackle this weird character issue you’re seeing after running npm run vuepress build. Those � symbols popping up between every character are almost always a sign of encoding mismatches somewhere in your build pipeline. Here’s a step-by-step breakdown of the most likely fixes:

  • Verify your Markdown file encodings
    First, make sure all your .md source files are saved in UTF-8 encoding (without BOM). Tools like VS Code let you check/change this via the bottom-right corner of the editor—click the current encoding label (like "GBK") and select "UTF-8", then choose "Save with encoding" to confirm. BOM (Byte Order Mark) can cause encoding conflicts in build tools, so sticking to UTF-8 without BOM is key.

  • Explicitly set charset in VuePress config
    Even though VuePress defaults to UTF-8, explicitly defining the charset in your config.js can prevent environment-specific encoding overrides. Add this to your config:

    module.exports = {
      head: [
        ['meta', { charset: 'utf-8' }],
        // Keep your existing head configurations here
      ]
    }
    
  • Fix your terminal’s encoding (Windows users especially)
    If you’re building on Windows, the default terminal (CMD/PowerShell) often uses a non-UTF-8 encoding (like GBK or CP1252). This can mess up how VuePress reads your source files. Run this command in your terminal before building to switch to UTF-8:

    chcp 65001
    

    Then re-run npm run vuepress build.

  • Clear VuePress cache and rebuild
    Cached files might be holding onto corrupted encoding data. Delete the cache folder and rebuild from scratch:

    # For macOS/Linux
    rm -rf node_modules/.cache/vuepress
    
    # For Windows (PowerShell)
    Remove-Item -Recurse -Force node_modules/.cache/vuepress
    

    Alternatively, use the --no-cache flag to skip caching entirely during build:

    npm run vuepress build --no-cache
    
  • Check for problematic plugins
    Third-party VuePress plugins (especially those that process Markdown content) can sometimes introduce encoding issues. Try temporarily disabling all non-essential plugins, then rebuild. If the problem goes away, re-enable plugins one by one to find the culprit.

Once you’ve tried these steps, open the generated dist/index.html in a text editor and confirm its encoding is UTF-8. You can also check in your browser (Chrome: Right-click → View page info → Encoding) to ensure the page is served with UTF-8.

内容的提问来源于stack exchange,提问作者quinlo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:25:42