【问题标题】:prettier: SyntaxError: Only void and foreign elements can be self closed更漂亮:语法错误:只有 void 和外部元素可以自关闭
【发布时间】:2020-12-11 11:01:12
【问题描述】:

当我运行 prettier 时出现此错误。

..\index.component.html
[error] ..\index.component.html: SyntaxError: Only void and foreign elements can be self closed "home-hero" (3:5)
[error]   1 |
[error]   2 |   <layout>
[error] > 3 |     <home-hero slot="hero" />
[error]     |     ^
[error]   4 |
[error]   5 |     <h3 slot="callout" />
[error]   6 |

但我想使用自我关闭标签。如何设置 prettier 忽略这个错误?

prettier schema 中,我没有看到任何关于“self”或类似内容的引用。

【问题讨论】:

  • 这是一个 angular/react/nativescript 应用程序吗?

标签: code-formatting prettier


【解决方案1】:

这实际上是下面线程中提到的HTML 标准的功能-

Are (non-void) self-closing tags valid in HTML5?

所有现代库like angular 都使用HTML5 标准作为模板,在这种情况下,用户定义的模板将被视为non-void,因此您必须使用适当的结束标签关闭标签。

这里是与voidnon-void相关的HTML标签描述的完整列表

https://developer.mozilla.org/en-US/docs/Web/HTML/Element

您还可以查看与技术相关的spec home-hero 是否允许自闭标签!

【讨论】:

    猜你喜欢
    • 2023-01-27
    • 1970-01-01
    • 1970-01-01
    • 2012-05-22
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    • 2021-04-06
    相关资源
    最近更新 更多