SAFE-Stack / SAFE-template

dotnet CLI template for SAFE project
MIT License
280 stars 87 forks source link

Following Quick Start guide fails to start API server #612

Open brokenthorn opened 1 month ago

brokenthorn commented 1 month ago

Hello!

I am trying SAFE for the very first time and I have problems getting the default quick start template to run correctly as is explained. It seems like the API server is not starting. I know this because I can load the client, i.e. I can see the web page, but there are no todos on it and I cannot add one either.

If I run the server manually in my IDE, then the UI also works or seems to work at least (the dotnet run log for example does not change even if I restart it). Here is how my IDE starts the server:

C:\Users\broke\AppData\Local\Programs\Rider\plugins\dpa\DotFiles\JetBrains.DPA.Runner.exe --handle=3100 --backend-pid=27604 --etw-collect-flags=67108622 --detach-event-name=dpa.detach.3100 D:/PharmaPOS/PharmaPOS.Web/src/Server/bin/Debug/net8.0/Server.exe

I've observed that all API calls seem to return HTTP 500.

First, here is the dotnet run log:

PS D:\PharmaPOS\PharmaPOS.Web> dotnet run
run Run
Building project with version: LocalBuild
Shortened DependencyGraph for Target Run:
<== Run
   <== InstallClient
      <== Clean

The running order is:
Group - 1
  - Clean
Group - 2
  - InstallClient
Group - 3
  - Run
Starting target 'Clean'
D:\PharmaPOS\PharmaPOS.Web\src\Client> "dotnet" fable clean --yes (In: false, Out: false, Err: false)
Fable 4.9.0: F# to JavaScript compiler
Minimum fable-library version (when installed from npm): 1.1.1

Thanks to the contributor! @MNie
Stand with Ukraine! https://standwithukraine.com.ua/

This will recursively delete all *.fs.js[.map] files in D:\PharmaPOS\PharmaPOS.Web\src\Client
Deleted output\fable_modules
Clean completed! Files deleted: 0
Finished (Success) 'Clean' in 00:00:00.2775343
Starting target 'InstallClient'
.> "C:\Users\broke\AppData\Local\fnm_multishells\29756_1717198915976\npm.CMD" install (In: false, Out: false, Err: false)

up to date, audited 155 packages in 725ms

21 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
Finished (Success) 'InstallClient' in 00:00:00.9163064
Starting target 'Run'
D:\PharmaPOS\PharmaPOS.Web\src\Shared> "dotnet" build (In: false, Out: false, Err: false)
  Determining projects to restore...
  Paket version 8.0.0+6bcb14ec191f11e984ff0e58016f5987a5cfa8f6
  The last full restore is still up to date. Nothing left to do.
  Total time taken: 0 milliseconds
  Restored D:\PharmaPOS\PharmaPOS.Web\src\Shared\Shared.fsproj (in 127 ms).
  Shared -> D:\PharmaPOS\PharmaPOS.Web\src\Shared\bin\Debug\net8.0\Shared.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.76
server: D:\PharmaPOS\PharmaPOS.Web\src\Server> dotnet watch run
client: D:\PharmaPOS\PharmaPOS.Web\src\Client> dotnet fable watch -o output -s --run npx vite
D:\PharmaPOS\PharmaPOS.Web\src\Server> "dotnet" watch run (In: false, Out: true, Err: true)D:\PharmaPOS\PharmaPOS.Web\src\Client> "dotnet" fable watch -o output -s --run npx vite (In: false, Out: true, Err: true)

client: Fable 4.9.0: F# to JavaScript compiler
client: Minimum fable-library version (when installed from npm): 1.1.1
client: Thanks to the contributor! @ptrelford
client: Stand with Ukraine! https://standwithukraine.com.ua/
client: Parsing Client.fsproj...
client: .> cmd /C dotnet restore Client.csproj -p:FABLE_COMPILER=true -p:FABLE_COMPILER_4=true -p:FABLE_COMPILER_JAVASCRIPT=true
client:   Determining projects to restore...
client:   Paket version 8.0.0+6bcb14ec191f11e984ff0e58016f5987a5cfa8f6
client:   The last full restore is still up to date. Nothing left to do.
client:   Total time taken: 0 milliseconds
server: dotnet watch ?? Started
client:   Paket version 8.0.0+6bcb14ec191f11e984ff0e58016f5987a5cfa8f6
client:   The last full restore is still up to date. Nothing left to do.
client:   Total time taken: 0 milliseconds
client:   Restored D:\PharmaPOS\PharmaPOS.Web\src\Client\Client.csproj (in 178 ms).
client:   1 of 2 projects are up-to-date for restore.
client: Some Nuget packages contain information about NPM dependencies that can be managed by Femto: https://github.com/Zaid-Ajaj/Femto
client: Project and references (63 source files) parsed in 3261ms
server: D:\PharmaPOS\PharmaPOS.Web\.paket\Paket.Restore.targets(171,5): error MSB3073: The command "dotnet paket restore" exited with code -532462766. [D:\PharmaPOS\PharmaPOS.Web\src\Shared\Shared.fsproj]
client: Loaded Feliz.HookAttribute from C:\Users\broke\.nuget\packages\feliz.compilerplugins\2.2.0\lib\netstandard2.0\Feliz.CompilerPlugins.dll
client: Loaded Feliz.ReactComponentAttribute from C:\Users\broke\.nuget\packages\feliz.compilerplugins\2.2.0\lib\netstandard2.0\Feliz.CompilerPlugins.dll
client: Loaded Feliz.ReactMemoComponentAttribute from C:\Users\broke\.nuget\packages\feliz.compilerplugins\2.2.0\lib\netstandard2.0\Feliz.CompilerPlugins.dll
client: Started Fable compilation...
server: D:\PharmaPOS\PharmaPOS.Web\.paket\Paket.Restore.targets(171,5): error MSB3073: The command "dotnet paket restore" exited with code -532462766. [D:\PharmaPOS\PharmaPOS.Web\src\Server\Server.fsproj]
server:
server: The build failed. Fix the build errors and run again.
server: dotnet watch ? Exited with error code 1
server: dotnet watch ? Waiting for a file to change before restarting dotnet...
client: Fable compilation finished in 6059ms
client: .> cmd /C npx vite
client: Watching ..
client:   VITE v5.0.13  ready in 185 ms
client:   ?  Local:   http://localhost:8080/
client:   ?  Network: use --host to expose
client:   ?  press h + enter to show help

Initial browser logs upon opening http://localhost:8080:

prelude.fs:15 Initial state: Model {Todos: RemoteData$1, Input: ''}
prelude.fs:15 Updated subs: FSharpList {head: null, tail: undefined}
prelude.fs:15 New message: Msg {tag: 1, fields: Array(1)}
prelude.fs:15 Updated state: Model {Todos: RemoteData$1, Input: ''}
prelude.fs:15 Updated subs: FSharpList {head: null, tail: undefined}
Http.fs:79 

       GET http://localhost:8080/api/ITodosApi/getTodos 500 (Internal Server Error)
(anonymous) @ Http.fs:79
(anonymous) @ Async.js:98
(anonymous) @ AsyncBuilder.js:76
onSuccess @ AsyncBuilder.js:89
(anonymous) @ Async.js:83
(anonymous) @ AsyncBuilder.js:76
(anonymous) @ AsyncBuilder.js:86
(anonymous) @ AsyncBuilder.js:76
(anonymous) @ AsyncBuilder.js:113
(anonymous) @ AsyncBuilder.js:76
(anonymous) @ AsyncBuilder.js:86
(anonymous) @ AsyncBuilder.js:76
(anonymous) @ AsyncBuilder.js:113
(anonymous) @ AsyncBuilder.js:76
(anonymous) @ Async.js:88
(anonymous) @ AsyncBuilder.js:76
(anonymous) @ AsyncBuilder.js:86
(anonymous) @ AsyncBuilder.js:76
(anonymous) @ AsyncBuilder.js:113
(anonymous) @ AsyncBuilder.js:76
startWithContinuations @ Async.js:147
start @ Async.js:136
startImmediate @ Async.js:139
(anonymous) @ cmd.fs:123
h @ Event.js:86
(anonymous) @ Event.js:23
Trigger @ Event.js:23
(anonymous) @ Timer.js:37
setTimeout (async)
set Enabled @ Timer.js:31
Timer_delay @ prelude.fs:33
Cmd_OfAsync_start @ cmd.fs:123
(anonymous) @ cmd.fs:139
(anonymous) @ cmd.fs:105
(anonymous) @ cmd.fs:34
(anonymous) @ cmd.fs:26
(anonymous) @ List.js:431
fold @ List.js:363
iterate @ List.js:430
Cmd_exec @ cmd.fs:26
processMsgs @ program.fs:190
ProgramModule_runWithDispatch @ program.fs:198
ProgramModule_runWith @ program.fs:205
(anonymous) @ hmr.fs:162
(anonymous) @ App.fs:20

And the failing initial call (the call to add a todo is similar):

Call stack:

(anonymous) @ http://localhost:8080/output/fable_modules/Fable.Remoting.Client.7.32.0/Http.fs.js:125
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Async.js:98
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:76
onSuccess @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:89
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Async.js:83
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:76
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:86
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:76
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:113
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:76
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:86
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:76
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:113
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:76
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Async.js:88
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:76
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:86
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:76
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:113
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/AsyncBuilder.js:76
startWithContinuations @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Async.js:147
start @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Async.js:136
startImmediate @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Async.js:139
(anonymous) @ http://localhost:8080/output/fable_modules/Fable.Elmish.4.1.0/cmd.fs.js:156
h @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Event.js:86
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Event.js:23
Trigger @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Event.js:23
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Timer.js:37
set Enabled @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/Timer.js:31
Timer_delay @ http://localhost:8080/output/fable_modules/Fable.Elmish.4.1.0/prelude.fs.js:19
Cmd_OfAsync_start @ http://localhost:8080/output/fable_modules/Fable.Elmish.4.1.0/cmd.fs.js:155
(anonymous) @ http://localhost:8080/output/Index.js:71
(anonymous) @ http://localhost:8080/output/fable_modules/Fable.Elmish.4.1.0/cmd.fs.js:130
(anonymous) @ http://localhost:8080/output/fable_modules/Fable.Elmish.4.1.0/cmd.fs.js:32
(anonymous) @ http://localhost:8080/output/fable_modules/Fable.Elmish.4.1.0/cmd.fs.js:12
(anonymous) @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/List.js:431
fold @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/List.js:363
iterate @ http://localhost:8080/output/fable_modules/fable-library.4.9.0/List.js:430
Cmd_exec @ http://localhost:8080/output/fable_modules/Fable.Elmish.4.1.0/cmd.fs.js:10
processMsgs @ http://localhost:8080/output/fable_modules/Fable.Elmish.4.1.0/program.fs.js:249
ProgramModule_runWithDispatch @ http://localhost:8080/output/fable_modules/Fable.Elmish.4.1.0/program.fs.js:263
ProgramModule_runWith @ http://localhost:8080/output/fable_modules/Fable.Elmish.4.1.0/program.fs.js:273
(anonymous) @ http://localhost:8080/output/App.js:126
(anonymous) @ http://localhost:8080/output/App.js:127

And screenshot:

image

Tools:

PS D:\PharmaPOS\PharmaPOS.Web> npm --version
10.8.1
PS D:\PharmaPOS\PharmaPOS.Web> node --version
v20.10.0
PS D:\PharmaPOS\PharmaPOS.Web> dotnet paket --version
Paket version 8.0.0+6bcb14ec191f11e984ff0e58016f5987a5cfa8f6
PS D:\PharmaPOS\PharmaPOS.Web> dotnet fable --version
4.9.0
PS D:\PharmaPOS\PharmaPOS.Web> 
brokenthorn commented 1 month ago

Also, the command that seems to fail when SAFE calls it, from my logs, runs perfectly if I run it:

PS D:\PharmaPOS\PharmaPOS.Web> dotnet paket restore       
Paket version 8.0.0+6bcb14ec191f11e984ff0e58016f5987a5cfa8f6
The last full restore is still up to date. Nothing left to do.
Total time taken: 0 milliseconds
jwthomson commented 1 month ago

If you go to src\Server and run the following command you can see the full exception: dotnet watch run -- -v d

Also, still in src\Server, does the error happen with dotnet run instead of dotnet watch run?

mattgallagher92 commented 3 weeks ago

@brokenthorn one of our devs has just had a similar issue (affecting only dotnet watch run) after updating to the latest version of Visual Studio. It seems that doing so installs a bundled .NET SDK 8.0.300. We haven't yet worked out why that might cause a problem with paket when using dotnet watch run, but have found a workaround: changing ./global.json to the below, where 8.0.XXX is the latest SDK version you have installed.

{
    "sdk": {
        "version": "8.0.XXX"
    }
}

You can see which .NET SDK versions you have installed using dotnet --list-sdks.

Please let us know if that helps you.

stefanwerner87 commented 3 weeks ago

@brokenthorn one of our devs has just had a similar issue (affecting only dotnet watch run) after updating to the latest version of Visual Studio. It seems that doing so installs a bundled .NET SDK 8.0.300. We haven't yet worked out why that might cause a problem with paket when using dotnet watch run, but have found a workaround: changing ./global.json to the below, where 8.0.XXX is the latest SDK version you have installed.

{
    "sdk": {
        "version": "8.0.XXX"
    }
}

You can see which .NET SDK versions you have installed using dotnet --list-sdks.

Please let us know if that helps you.

i have the same issue, however your solution doesnt work for me :/

@jwthomson dotnet run works for me instead of dotnet watch run

isaacabraham commented 3 weeks ago

@stefanwerner87 Hi. We are fairly confident that this is due to a bug introduced in .NET 8.0.300. I would recommend that you install an older version of .NET 8 (side-by-side) e.g. 8.0.206 (https://dotnet.microsoft.com/en-us/download/dotnet/8.0). Then change your SDK to:

{
    "sdk": {
        "version": "8.0.206"
    }
}

WITHOUT any "minor update" roll forward.

Hope that that helps - let me know how you get on.

jwthomson commented 1 week ago

@brokenthorn did you have a chance to test out the potential fix described by Isaac?

milhollin commented 1 week ago

I was struggling with the same issue for the last few days before I thought to look here. I tried the fix and it worked. Thank you!