Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js uses not defined value #329

Closed
hesxenon opened this issue Nov 15, 2022 · 4 comments
Closed

js uses not defined value #329

hesxenon opened this issue Nov 15, 2022 · 4 comments

Comments

@hesxenon
Copy link

Hi, I'm just trying to get started with Fable (coming from JS) in general and thought Fable.Remoting looked really nice.

However it seems that following the "from scratch" guide for suave produces broken JS and I don't know why.

.fsproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="../contracts/Contracts.fs" />
    <Compile Include="Server.fs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Update="FSharp.Core" Version="6.0.7" />
    <PackageReference Include="Fable.Core" Version="3.7.1" />
    <PackageReference Include="Fable.Remoting.Suave" Version="4.32.0" />
  </ItemGroup>

</Project>
Server.fs
module Server

open Suave
open Suave.Filters
open Suave.Successful
open Fable.Remoting.Server
open Fable.Remoting.Suave

let todoStore: Contracts.todoStore = { test = async { return "Hello World" } }

let api: WebPart =
  Remoting.createApi () |> Remoting.fromValue todoStore |> Remoting.buildWebPart

startWebServer defaultConfig api
Server.fs.js
import { singleton } from "./fable_modules/fable-library.3.7.20/AsyncBuilder.js";
import { todoStore as todoStore_1 } from "../contracts/Contracts.fs.js";

export const todoStore = new todoStore_1(singleton.Delay(() => singleton.Return("Hello World")));

export const api = Fable_Remoting_Suave_Remoting_buildWebPart(Fable_Remoting_Server_Remoting_fromValue(todoStore, Fable_Remoting_Server_Remoting_createApi()));

Suave_Web_startWebServer(Suave_Web_defaultConfig, api);

//# sourceMappingURL=Server.fs.js.map

Fable_Remoting_Suave_Remoting_buildWebPart obviously doesn't exist in the scope where it's used. Any ideas why and what I did wrong?

@kerams
Copy link
Collaborator

kerams commented Nov 15, 2022

Suave is the web server - it runs on .NET and you should not compile it with Fable.

@hesxenon
Copy link
Author

hesxenon commented Nov 15, 2022 via email

@kerams
Copy link
Collaborator

kerams commented Nov 15, 2022

Fable.Remoting.Client package is what you use in the client project which you compile with Fable. Fable.Remoting.(Suave | Giraffe | etc.) on the other hand are purely .NET packages, which are to be used in the corresponding web server, so that it knows how to handle the Remoting RPC traffic. Both sides are needed - it does not make sense to use one without the other. Fable.Remoting is the name of this project and therefore it is also the main namespace for all Nuget packages, even though most of them aren't technically Fable-compatible.

@hesxenon
Copy link
Author

hesxenon commented Nov 15, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants