yaml 扩展错误(类型不正确。预期 "string".yaml-schema: pubspec.yaml )

yaml extension error ( Incorrect type. Expected "string".yaml-schema: pubspec.yaml )

最近我创建了一个 flutter 项目并打开了“YAML”,从“YAML”扩展中得到了一些错误,我该如何解决这个问题,唯一的解决方案是卸载扩展还是如何在不卸载此扩展的情况下解决这个问题

尝试了 flutter clean、修复等......但没有任何帮助,

获取错误是

1 类型不正确。预期的“字符串”.yaml-schema:pubspec.yaml

2 属性 flutter 不是 allowed.yaml-schema: pubspec.yaml

3 属性 cupertino_icons 不是 allowed.yaml-架构:pubspec.yaml

4 属性 flutter_test 不是 allowed.yaml-架构:pubspec.yaml

5 等等......

使用的flutter版本是2.8.1

“YAML”(扩展)版本 v1.5.0

YAML 扩展使用不正确的架构来验证您​​的 YAML 文件。确保:

  • 您的文件确实包含正确的 # yaml-language-server: $schema=<urlToTheSchema> 评论,或者至少 没有 包含错误的评论。
  • 您的 yaml.schemas 设置不会通过 glob 模式将您的文件与不正确的架构相关联。

正确的模式应该是 https://json.schemastore.org/pubspec.json。另见 Associating Schemas

从今天下午开始,我在 VSCode 上遇到了同样的问题,之前一切正常。我试过通过 # yaml-language-server: $schema=<urlToTheSchema>yaml.schemas 设置强制架构,但没有成功。

编辑:可能与升级到 yaml 扩展 v1.5.0 有关(参见:https://github.com/redhat-developer/vscode-yaml/issues/708) 暂时降级回 1.4.0 不再抛出错误。

我已经卸载yaml扩展 并重新安装 re-open vs 代码 它为我解决了问题

对我来说,在 VsCode 的扩展中,我查找了 YAML,我看到它旁边有一个“需要重新加载”。重新加载,错误消失了。现在都修好了。

请将 VSCode 的 YAML 扩展名至少更新为 1.5.1 以解决错误。 Flutter 也会像错误一样工作。

我通过重新加载扩展修复了我的问题。我转到我的扩展选项卡,需要重新加载 YAML 扩展。

It does not show here but instead on the left of "Disable", there was a message telling me that I needed to reload the extension.

我重新加载 YAML 扩展,错误消失了