elmish / browser

Routing and Navigation for browser apps
https://elmish.github.io/browser
Other
35 stars 20 forks source link

Fable compilation error "A unique overload for method 'TryParse' could not be determined..." #22

Closed lambdakris closed 5 years ago

lambdakris commented 5 years ago

Description

Hello, I am getting some sort of Fable error during the compilation phase but it does not seem to actually prevent the build from completing and the program from running correctly. The error is the following:

...
[./src/Program.fs] 3.25 KiB {main} [built]
[./src/Program.fsproj] 29 bytes {main} [built]
    + 48 hidden modules

ERROR in ./.fable/Fable.Elmish.Browser.3.0.0/parser.fs
Module Error (from ./node_modules/fable-loader/index.js):
C:/Users/usr/Code/Hobby/Voyage/frontend/.fable/Fable.Elmish.Browser.3.0.0/parser.fs(272,19): (272,46) error FSHARP: A unique overload for method 'TryParse' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: System.Int32.TryParse(s: System.ReadOnlySpan<char>, result: byref<int>) : bool, System.Int32.TryParse(s: string, result: byref<int>) : bool (code 41)
 @ ./src/Program.fs 3:0-98 29:27-30 29:56-60 29:68-71 29:97-101 29:112-115 29:142-146 31:11-16 66:11-20
 @ ./src/Program.fsproj
i 「wdm」: Failed to compile.
i 「wdm」: Compiling...
Parsing ./src/Program.fsproj...
fable: Compiled src\Program.fs
fable: Compiled .fable\Fable.Elmish.Browser.3.0.0\parser.fs
...

Repro code

Here is a minimal example.

  1. npm install
  2. cd src
  3. dotnet restore
  4. cd ..
  5. npm run start

example.zip

Expected and actual results

The expected result would be for there to be no Fable compilation error. The actual result is the error specified above during the Fable compilation process.

Related information

Sneaky question while I'm at it...

How would one do nested routing? I can't envision how that would work with the whole composed MVU architecture thing. Do you know of any examples in the wild that I might check out?

et1975 commented 5 years ago

Thanks for the report. I think this is the new spans support, can you add output from dotnet --info please?

et1975 commented 5 years ago

Can you give 3.0.1 a spin?

On Sun, May 12, 2019 at 9:50 AM Yevgeniy Tolmachev eugene@tolmachev.ca wrote:

Thanks for the report. I think this is the new spans support, can you add output from dotnet --info please?

lambdakris commented 5 years ago

I am unable to get the build working so I can't verify if the changes introduced in 3.0.1 fixed it. Just in case, below is the dotnet --info in case you still need it...

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview5-011568
 Commit:    b487ff10aa

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\

Host (useful for support):
  Version: 3.0.0-preview5-27626-15
  Commit:  61f30f5a23

.NET Core SDKs installed:
  2.1.600 [C:\Program Files\dotnet\sdk]
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.2.105 [C:\Program Files\dotnet\sdk]
  2.2.200 [C:\Program Files\dotnet\sdk]
  2.2.202 [C:\Program Files\dotnet\sdk]
  3.0.100-preview5-011568 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview5-19227-01 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
et1975 commented 5 years ago

Does https://elmish.github.io/elmish/parent-child.html help?

lambdakris commented 5 years ago

I finally got the change to get the elmish/browser build working, but when I tried referencing the Fable.Elmish.Browser.dll directly from the example to test the change, I got additional errors about missing references. I guess I should wait until you have time to update the nuget package.

et1975 commented 5 years ago

Are you saying package 3.0.1 doesn't fix it for you? In any case you can switch your build to use sdk version to 2.2.x and it should work for now.

lambdakris commented 5 years ago

Ahh, thing is, I don't see the 3.0.1 package on NuGet.org. That's what threw me off initially, and why I was trying to build Fable.Elmish.Browser myself and reference directly...

lambdakris commented 5 years ago

Oh, just to clarify, the error is there when targeting netcoreapp2.2 and netcoreapp2.1 as well. Only netcoreapp2.0 and lower compiles without error. I think this is still consistent with your diagnosis that it is due to the introduction of Span.

et1975 commented 5 years ago

It's not really what you target, it's the complier you use, you have beta of v3 as the default. Create this file in the root of your solution to use v2.2 sdk: https://docs.microsoft.com/en-us/dotnet/core/tools/global-json

lambdakris commented 5 years ago

Well, I tried pinning the SDK to 2.2 and 2.1 in the global.json file as well, but it doesn't get rid of the error (I can confirm that it picks up the pinned SDK with dotnet --version). However, if the issue is like you say due to Span, then that is still what one would expect to see since I believe Span was introduced with .NET Core 2.1, is that about right?

Luiz-Monad commented 5 years ago

I also tried to pin the SDK, it didn't work.

What solved the problem was specifying that value is a string, not a span. https://github.com/elmish/browser/blob/cc55f78bffbc3fb4aeed7cac3259cf49a089cb81/src/parser.fs#L269

edit: I've noticed it was fixed in the 3.0.1 version, but I was pulling 3.0.0 from nuget.

Sorry for the inconvenience.

Config:

.NET Core SDK (reflecting any global.json):
 Version:   2.2.200
 Commit:    27f814f6ba

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.200\

Host (useful for support):
  Version: 2.2.5
  Commit:  0a3c9209c0

.NET Core SDKs installed:
  2.0.0 [C:\Program Files\dotnet\sdk]
  2.2.101 [C:\Program Files\dotnet\sdk]
  2.2.107 [C:\Program Files\dotnet\sdk]
  2.2.200 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
et1975 commented 5 years ago

Sounds like 3.0.1 solves the problem, released the package.