SAFE-Stack / SAFE-template

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

SAFE client debugging in VS Code fails to compile #554

Closed geysernrd closed 1 year ago

geysernrd commented 1 year ago

Once I pin Fable.Elmish to version 3.1.0 (per this issue), I can run a SAFE Stack app with "dotnet run".

If I try to debug, the server starts fine, but if I use the debug command ("dotnet fable watch -o output -s --run npm run start"), these compile errors occur:

.\Helpers.fs(57,21): (57,39) error FSHARP: The type referenced through 'System.Collections.Immutable.IImmutableDictionary`2' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections.Immutable'. (code 74)
.\Helpers.fs(59,27): (59,47) error FSHARP: The type referenced through 'System.Collections.Immutable.IImmutableDictionary`2' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections.Immutable'. (code 74)
.\Helpers.fs(60,28): (60,59) error FSHARP: The type referenced through 'System.Collections.Immutable.IImmutableDictionary`2' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections.Immutable'. (code 74)
.\Helpers.fs(1,1): error EXCEPTION: Cannot find inline member: Fake.Core.String_isNotNullOrEmpty
   at Fable.Transforms.State.CompilerImpl.Fable.Compiler.GetInlineExpr(String memberUniqueName) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\State.fs:line 259
   at Fable.Transforms.FSharp2Fable.Util.inlineExpr(IFableCompiler com, Context ctx, FSharpOption`1 r, Type t, FSharpList`1 genArgs, FSharpOption`1 callee, CallInfo info, String membUniqueName) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\FSharp2Fable.Util.fs:line 1834
   at Fable.Transforms.FSharp2Fable.Util.|Inlined|_|(IFableCompiler com, Context ctx, FSharpOption`1 r, Type t, FSharpList`1 genArgs, FSharpOption`1 callee, CallInfo info, FSharpMemberOrFunctionOrValue 
memb) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\FSharp2Fable.Util.fs:line 1883
   at Fable.Transforms.FSharp2Fable.Util.makeCallWithArgInfo(IFableCompiler com, Context ctx, FSharpOption`1 r, Type typ, FSharpList`1 genArgs, FSharpOption`1 callee, FSharpMemberOrFunctionOrValue memb, CallInfo callInfo) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\FSharp2Fable.Util.fs:line 1914
   at Fable.Transforms.FSharp2Fable.Util.makeCallFrom(IFableCompiler com, Context ctx, FSharpOption`1 r, Type typ, FSharpList`1 genArgs, FSharpOption`1 callee, FSharpList`1 args, FSharpMemberOrFunctionOrValue memb) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\FSharp2Fable.Util.fs:line 1988
   at Fable.Transforms.FSharp2Fable.Compiler.transformExpr@703-36.Invoke(Context ctx) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\FSharp2Fable.fs:line 703
   at MonadicTrampoline.run[a](Thunk`1 _arg1) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\MonadicTrampoline.fs:line 8
   at MonadicTrampoline.Bind@16.Invoke(Unit unitVar0) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\MonadicTrampoline.fs:line 16
   at MonadicTrampoline.run[a](Thunk`1 _arg1) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\MonadicTrampoline.fs:line 8
   at MonadicTrampoline.Bind@16.Invoke(Unit unitVar0) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\MonadicTrampoline.fs:line 16
   at MonadicTrampoline.run[a](Thunk`1 _arg1) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\MonadicTrampoline.fs:line 8
   at MonadicTrampoline.Bind@16.Invoke(Unit unitVar0) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\MonadicTrampoline.fs:line 16
   at MonadicTrampoline.run[a](Thunk`1 _arg1) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\MonadicTrampoline.fs:line 8
   at Fable.Transforms.FSharp2Fable.Compiler.transformMemberFunction(IFableCompiler com, Context ctx, Boolean isPublic, String name, String fullDisplayName, FSharpMemberOrFunctionOrValue memb, FSharpList`1 args, FSharpExpr body) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\FSharp2Fable.fs:line 1217
   at Fable.Transforms.FSharp2Fable.Compiler.transformMemberFunctionOrValue(IFableCompiler com, Context ctx, FSharpMemberOrFunctionOrValue memb, FSharpList`1 args, FSharpExpr body) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\FSharp2Fable.fs:line 1265
   at Fable.Transforms.FSharp2Fable.Compiler.transformMemberDecl(FableCompiler com, Context ctx, FSharpMemberOrFunctionOrValue memb, FSharpList`1 args, FSharpExpr body) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\FSharp2Fable.fs:line 1342
   at Fable.Transforms.FSharp2Fable.Compiler.transformDeclarations@1391.Invoke(FSharpImplementationFileDeclaration fsDecl) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\FSharp2Fable.fs:line 1416   
   at Microsoft.FSharp.Primitives.Basics.List.collectToFreshConsTail[T,TResult](FSharpFunc`2 f, FSharpList`1 list, FSharpList`1 cons) in C:\Users\alfon\repos\fsharp\src\fsharp\FSharp.Core\local.fs:line 
435
   at Microsoft.FSharp.Primitives.Basics.List.collect[T,TResult](FSharpFunc`2 f, FSharpList`1 list) in C:\Users\alfon\repos\fsharp\src\fsharp\FSharp.Core\local.fs:line 443
   at Microsoft.FSharp.Primitives.Basics.List.collectToFreshConsTail[T,TResult](FSharpFunc`2 f, FSharpList`1 list, FSharpList`1 cons) in C:\Users\alfon\repos\fsharp\src\fsharp\FSharp.Core\local.fs:line 
435
   at Microsoft.FSharp.Primitives.Basics.List.collect[T,TResult](FSharpFunc`2 f, FSharpList`1 list) in C:\Users\alfon\repos\fsharp\src\fsharp\FSharp.Core\local.fs:line 443
   at Fable.Transforms.FSharp2Fable.Compiler.transformFile(Compiler com) in C:\Users\alfon\repos\Fable\src\Fable.Transforms\FSharp2Fable.fs:line 1707
   at Fable.Cli.Main.Util.compileFile@178-1.Invoke(Unit unitVar) in C:\Users\alfon\repos\Fable\src\Fable.Cli\Main.fs:line 178
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in C:\Users\alfon\repos\fsharp\src\fsharp\FSharp.Core\async.fs:line 
447
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in C:\Users\alfon\repos\fsharp\src\fsharp\FSharp.Core\async.fs:line 104
.\Build.fs(1,1): error FABLE: Cannot find Farmer.OS constructor

As with the Fable.Elmish error, I've confirmed that this occurs even with a new SAFE app created by the latest SAFE template.

mattgallagher92 commented 1 year ago

Hi @geysernrd, thanks for reporting this issue.

I was able to run the suggested command fine:

image

matt@matt-framework:~/dev-cit/cit/safe-template-554/src/Client$ dotnet fable watch -o output -s --run npm start                                                    
Fable: F# to JS compiler 3.7.5
Stop Russian aggression against Ukraine!

Parsing Client.fsproj...
Retrieving project options from cache, in case of issues run `dotnet fable clean` or try `--noCache` option.
Project and references (120 source files) parsed in 86ms

.> npm start

> start
> webpack-dev-server --mode development

Bundling for run - development ...
Loaded Feliz.HookAttribute from ../../../../../.nuget/packages/feliz.compilerplugins/1.8.0/lib/netstandard2.0/Feliz.CompilerPlugins.dll
Loaded Feliz.ReactComponentAttribute from ../../../../../.nuget/packages/feliz.compilerplugins/1.8.0/lib/netstandard2.0/Feliz.CompilerPlugins.dll
Loaded Feliz.ReactMemoComponentAttribute from ../../../../../.nuget/packages/feliz.compilerplugins/1.8.0/lib/netstandard2.0/Feliz.CompilerPlugins.dll
<i> [webpack-dev-server] [HPM] Proxy created: /api/**  -> http://localhost:5000
<i> [webpack-dev-server] [HPM] Proxy created: /socket/**  -> http://localhost:5000
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:8080/
<i> [webpack-dev-server] On Your Network (IPv4): http://192.168.0.31:8080/
<i> [webpack-dev-server] Content not from webpack is served from '/home/matt/dev-cit/cit/safe-template-554/src/Client/public' directory                              
<i> [webpack-dev-server] 404s will fallback to '/index.html'
asset vendors-node_modules_react-dom_index_js-node_modules_remotedev_lib_index_js-node_modules_webp-2931a1.js 3.29 MiB [emitted] (id hint: vendors)
asset app.js 3.01 MiB [emitted] (name: app)
asset runtime.js 43.3 KiB [emitted] (name: runtime)
asset index.html 704 bytes [emitted]
Entrypoint app 6.34 MiB = runtime.js 43.3 KiB vendors-node_modules_react-dom_index_js-node_modules_remotedev_lib_index_js-node_modules_webp-2931a1.js 3.29 MiB app.js 3.01 MiB
runtime modules 28.2 KiB 14 modules
modules by path ./src/Client/output/ 1.01 MiB
  modules by path ./src/Client/output/fable_modules/fable-library.3.7.5/ 596 KiB 45 modules
  modules by path ./src/Client/output/fable_modules/Fable.SimpleJson.3.23.0/*.js 164 KiB 8 modules
  modules by path ./src/Client/output/fable_modules/Fable.Remoting.Client.7.19.0/*.js 30.5 KiB 5 modules                                                                                
  modules by path ./src/Client/output/fable_modules/Fable.Elmish.3.1.0/*.js 15.3 KiB 4 modules
  modules by path ./src/Client/output/fable_modules/Thoth.Json.6.0.0/*.js 97.8 KiB 4 modules
  modules by path ./src/Client/output/fable_modules/Fable.Elmish.HMR.5.2.0/*.js 6.32 KiB 3 modules
  modules by path ./src/Client/output/*.js 18.8 KiB 2 modules
  modules by path ./src/Client/output/fable_modules/Fable.Elmish.React.3.0.1/*.js 5.29 KiB 2 modules                                                                                
  modules by path ./src/Client/output/fable_modules/Fable.Elmish.Debugger.3.3.0/*.js 6.37 KiB 2 modules                                                                                
  modules by path ./src/Client/output/fable_modules/Fable.Parsimmon.4.1.0/*.js 35.2 KiB 2 modules
modules by path ./node_modules/ 1.22 MiB 55 modules
webpack 5.65.0 compiled successfully in 1152 ms
Fable compilation finished in 5359ms

However, having seen that you're getting errors in ./Helpers.fs and ./Build.fs, I guessed that you're running this command from the repo root. Indeed, if I do that, I see the same errors that you reported:

matt@matt-framework:~/dev-cit/cit/safe-template-554$ dotnet fable watch -o output -s --run npm start                                                                                                 
...
./Helpers.fs(55,21): (55,39) error FSHARP: The type referenced through 'System.Collections.Immutable.IImmutableDictionary`2' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections.Immutable'. (code 74)
...

I'll close this issue on the assumption that things will work fine for you too if you run the command in the ./src/Client directory, but will make a PR against the docs site to make the instructions clearer. Please report back if this issue persists though.

geysernrd commented 1 year ago

Hi @mattgallagher92,

You're right, that was my mistake! I hadn't done this in a while and forgot I needed to change directories.

Thanks for the help!