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

VS Code中Bicep加载JSON文件报错,如何忽略文件未找到错误?

解决VS Code中Bicep加载不存在JSON文件的报错问题

问题场景

我在main.bicep中使用以下代码引用上级目录的JSON文件:

var groupAndPrincipalIDs = loadJsonContent('../groupAndPrincipalIDs.json')

该JSON文件由一条流水线生成,其余流水线依赖这个Bicep文件部署资源。本地开发时仓库中没有这个JSON文件,VS Code报错:

An error occurred reading file. Could not find file 'c:\UserX*Repo*\groupAndPrincipalIDs.json

之前尝试在仓库外的上级目录创建.vscode/settings.json并添加以下配置,但未生效:

{
     "bicep.build.targetScope": "file",
     "bicep.build.file": "main.bicep",
     "bicep.build.onFileOpen": {
        "ignoreFileNotFound": ["../groupAndPrincipalIDs.json"]
     }
}

正确解决步骤

  1. 将.vscode文件夹移至仓库根目录
    VS Code的工作区设置优先读取当前打开仓库(工作区)内的.vscode/settings.json,仓库外的配置不会被当前工作区识别,所以需要把.vscode文件夹放到仓库根目录下。

  2. 使用正确的Bicep配置项
    之前的bicep.build.onFileOpen.ignoreFileNotFound并非有效配置项,正确的做法是针对Bicep linter的file-not-found规则设置忽略路径:

{
  "bicep.linter.rules": {
    "file-not-found": {
      "level": "warning", // 可选:设为"off"可完全关闭该错误提示
      "ignorePaths": ["../groupAndPrincipalIDs.json"]
    }
  }
}
  1. 生效配置
    保存settings.json后,可通过以下方式让配置生效:
  • 重新打开main.bicep文件
  • 打开命令面板(Ctrl+Shift+P),执行Restart Bicep Language Server命令

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 02:01:08