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

将Giraffe项目Views模块移至Views.fs后出现FS0003编译错误

解决Giraffe迁移Views模块后的_rel编译错误

问题原因

你碰到的FS0003错误,核心原因是**_rel、_href这类HTML属性函数都属于Giraffe.ViewEngine.HtmlAttributes子模块**,但迁移后的Views.fs只引用了Giraffe.ViewEngine根命名空间,没显式打开HtmlAttributes模块,导致编译器把_rel当成了普通值,而非可调用的函数。

之前在Program.fs里能正常编译,是因为默认模板的Program.fs已经隐式或显式引入了HtmlAttributes模块(比如open Giraffe会间接关联子模块,或者代码里有单独的open语句),移到独立文件后这个上下文就丢失了。

解决办法

在Views.fs开头添加HtmlAttributes模块的引用即可:

module Views

open Giraffe.ViewEngine
open Giraffe.ViewEngine.HtmlAttributes // 新增这一行

let layout (content : XmlNode list) =
    html [] [
        head [] [
            title [] [ str "GiraffeApp" ]
            link [ _rel "stylesheet"; _href "/css/site.css" ]
        ]
        body [] content
    ]

如果不想全局打开模块,也可以直接用模块前缀调用属性函数:

link [ HtmlAttributes._rel "stylesheet"; HtmlAttributes._href "/css/site.css" ]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 06:15:03