Skip to content

Overview code examples don't build #25

@mjarosie

Description

@mjarosie

Hi,

I just started getting my head around WebSharper 2 days ago, so I thought sharing my "fresh" point of view could be beneficial to the project.

The first thing I've tried after getting set up with .NET, WebSharper templates and VSCode F# extension was to build example code snippets that are listed in the Overview page. Unfortunately, even the "Hello world!" example doesn't build successfully (unless I'm doing something wrong). The first obstacle that I came across was that the page doesn't mention where exactly should these snippets be put in order to make them work. After quite a bit of digging I ended up on the WebSharper v3 documentation which describes how to run example snippets which suggests to use SPA template and replace its content.

Taking the "Hello world!" snippet:

module YourApp

open WebSharper
open WebSharper.Sitelets

[<Website>]
    let Main = Application.Text (fun ctx -> "Hello World!")

I've generated the SPA from the template (dotnet new websharper-spa -lang f# -n HelloWorld) and replaced the content of Client.fs with the given code (without replacing the namespace declaration and leaving Startup.fs intact), which results in the following:

namespace HelloWorld

module YourApp

open WebSharper
open WebSharper.Sitelets

[<Website>]
    let Main = Application.Text (fun ctx -> "Hello World!")

dotnet run results in:

C:\source\websharper-samples\HelloWorld\Client.fs(5,1,5,5): parse error FS0010: Unexpected start of structured construct in definition. Expected '=' or other token. [C:\source\websharper-samples\HelloWorld\HelloWorld.fsproj]
C:\source\websharper-samples\HelloWorld\Client.fs(9,1,9,60): parse error FS0010: Incomplete structured construct at or before this point in implementation file [C:\source\websharper-samples\HelloWorld\HelloWorld.fsproj]

Googling for the first error description I ended up on this SO question, so I've tried defining the "local module" instead:

namespace HelloWorld

module YourApp =

    open WebSharper
    open WebSharper.Sitelets

    [<Website>]
        let Main = Application.Text (fun ctx -> "Hello World!")

now dotnet run results in:

FSC : WebSharper error FS9001: Error during bundling: Missing entry point or export. Add SPAEntryPoint attribute to a static method without arguments, or JavaScriptExport on types/methods to expose them. [C:\source\websharper-samples\HelloWorld\HelloWorld.fsproj]

The build failed. Fix the build errors and run again.

After a bit of digging I ended up replacing Website attribute with SPAEntryPoint, which results in:

namespace HelloWorld

module YourApp =

    open WebSharper
    open WebSharper.Sitelets

    [<SPAEntryPoint>]
        let Main = Application.Text (fun ctx -> "Hello World!")

Output of dotnet run:

C:\source\websharper-samples\HelloWorld\Client.fs(9,20,9,64): WebSharper error FS9001: Type not found in JavaScript compilation: WebSharper.Application [C:\source\websharper-samples\HelloWorld\HelloWorld.fsproj]

The build failed. Fix the build errors and run again.

Googling for this error doesn't give any results. Later I've been trying to modify the code based on the initial content of the template, I've also tried using the let Run = (Main ()).AppendTo "entrypoint" mentioned in v3 documentation (which I guess doesn't work because the API changed between v3 and v4), all to no avail.

So far I can't solve this problem, after at least a few hours of fighting against the "Hello world!" I just gave up... I've followed other WebSharper tutorials with greater success since then, but I think examples from the main page of the documetation which actually work would improve the new starter experience significantly. I'd be keen on trying to contribute to the documentation as well, but I'm still not even able to build these examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions