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

编译Pandoc源码遇Stack报错:ghc-options字段解析失败($locals无效)

解决Stack编译Pandoc时的"Invalid package name: $locals"错误

Ah, I've run into this exact issue before when building Pandoc with an older Stack version! Let's break down what's happening and how to fix it:

问题根源

The error you're seeing is almost certainly due to using an outdated version of Stack. The $locals syntax is a relatively recent addition to Stack—it's a special variable that refers to all local packages in your project. Older Stack versions don't recognize this variable, so they mistakenly try to parse $locals as a literal package name, which throws that "invalid package name" error.

解决方案步骤

  1. 升级Stack到最新版本
    这是最关键的修复步骤。在终端运行以下命令更新Stack:

    stack upgrade
    

    如果是Windows系统,可能需要以管理员权限打开终端执行该命令。

  2. 清理完整构建缓存(可选但推荐)
    即使升级了Stack,旧的构建缓存有时仍会导致遗留问题。执行以下命令清空完整缓存:

    stack clean --full
    
  3. 重新构建Pandoc
    回到Pandoc源码目录,再次运行构建命令:

    stack build
    

额外检查(若升级后仍有问题)

如果升级后依然报错,可以检查项目的stack.yaml文件,确认使用$locals的ghc-options部分格式是否正确——正确的写法大致如下:

ghc-options:
  $locals: -Wall -Werror

不过如果你严格按照官方构建步骤操作,这大概率不是问题所在,版本不匹配才是最常见的诱因。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 03:39:11