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

Webpack fails with 'Original message: Invalid value' #2251

Closed
absolutejam opened this issue Nov 6, 2020 · 9 comments
Closed

Webpack fails with 'Original message: Invalid value' #2251

absolutejam opened this issue Nov 6, 2020 · 9 comments

Comments

@absolutejam
Copy link

absolutejam commented Nov 6, 2020

Description

(Apologies for creating this as an issue, but I've tried the web channel in the F# Slack to no avail and didn't know what other avenues might be appropriate for a debugging-focussed discussion)

So, I have a project that I was working on but I'd taken a break (half-way through a big spike), and when I've come back to it, I can no longer build the frontend.

I have tried stripping chunks out (where possible) and rolling back to a previous commit, but at the moment I'm not sure where the issue is even originating.

A simple dotnet build src/Client/Client.fsproj works and VSCode presents no actual errors that would stop compilation, but when I try to run my Fake build script which calls yarn webpack-dev-server --verbose, I get the following error:

✖ 「wdm」: Hash: c92d3824fd4d2675101c
Version: webpack 4.41.6
Time: 79483ms
Built at: 06/11/2020 09:12:30
               Asset        Size             Chunks             Chunk Names
              app.js    35.5 KiB                app  [emitted]  app
          index.html  1020 bytes                     [emitted]
            style.js    6.84 MiB              style  [emitted]  style
vendors~app~style.js     896 KiB  vendors~app~style  [emitted]  vendors~app~style
    vendors~style.js    45.1 KiB      vendors~style  [emitted]  vendors~style
Entrypoint app = vendors~app~style.js app.js
Entrypoint style = vendors~app~style.js vendors~style.js style.js
[0] multi (webpack)-dev-server/client?http://0.0.0.0:9090 (webpack)/hot/dev-server.js ./src/Client/Client.fsproj 52 bytes {app} [built]
[3] multi (webpack)-dev-server/client?http://0.0.0.0:9090 (webpack)/hot/dev-server.js ./src/Client/css/tailwind-source.css 52 bytes {style} [built]
[./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/src/index.js!./src/Client/css/tailwind-source.css] ./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/src!./src/Client/css/tai
lwind-source.css 2.44 MiB {style} [built]
[./node_modules/strip-ansi/index.js] 161 bytes {vendors~app~style} [built]
[./node_modules/style-loader/lib/addStyles.js] 10.2 KiB {vendors~style} [built]
[./node_modules/webpack-dev-server/client/index.js?http://0.0.0.0:9090] (webpack)-dev-server/client?http://0.0.0.0:9090 4.29 KiB {vendors~app~style} [built]
[./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.51 KiB {vendors~app~style} [built]
[./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.53 KiB {vendors~app~style} [built]
[./node_modules/webpack-dev-server/client/utils/createSocketUrl.js] (webpack)-dev-server/client/utils/createSocketUrl.js 2.89 KiB {vendors~app~style} [built]
[./node_modules/webpack-dev-server/client/utils/log.js] (webpack)-dev-server/client/utils/log.js 964 bytes {vendors~app~style} [built]
[./node_modules/webpack-dev-server/client/utils/reloadApp.js] (webpack)-dev-server/client/utils/reloadApp.js 1.59 KiB {vendors~app~style} [built]
[./node_modules/webpack-dev-server/client/utils/sendMessage.js] (webpack)-dev-server/client/utils/sendMessage.js 402 bytes {vendors~app~style} [built]
[./node_modules/webpack/hot/dev-server.js] (webpack)/hot/dev-server.js 1.59 KiB {vendors~app~style} [built]
[./src/Client/Client.fsproj] 413 bytes {app} [built] [failed] [1 error]
[./src/Client/css/tailwind-source.css] 1.25 KiB {style} [built]
    + 29 hidden modules

ERROR in ./src/Client/Client.fsproj
Module build failed (from ./node_modules/fable-loader/index.js):
Error: The exception has been reported. This internal exception should now be caught at an error recovery point on the stack. Original message: Invalid value)
    at /Users/james/Documents/realmweaver/realmweaver/node_modules/fable-loader/index.js:98:22
    at processTicksAndRejections (internal/process/task_queues.js:82:5)
 @ multi ./src/Client/Client.fsproj app[0]
Child html-webpack-plugin for "index.html":
     1 asset
    Entrypoint undefined = index.html
    [./node_modules/html-webpack-plugin/lib/loader.js!./src/Client/index.html] 1010 bytes {0} [built]
    [./node_modules/lodash/lodash.js] 528 KiB {0} [built]
    [./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 472 bytes {0} [built]
    [./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 497 bytes {0} [built]
ℹ 「wdm」: Failed to compile.

I've tried the usual suspects of clearing bin, obj & node_modules. Honestly, I'm kinda stumped to the actual flow of debugging something that's happening at the point.

Repro code

Erm, I can provide this but it's an entire (messy & WIP) codebase, so I was more hoping for hints on how to debug something this cryptic to begin with and maybe I can narrow it down to something that might be causing the issue.

Expected and actual results

Please provide the expected and actual results.

Related information

  • Fable version: 2.13.0
  • Fable-loader: 2.1.9
  • Dotnet SDK: 5.0.100-rc.1.20452.10
  • Operating system: macOS
@alfonsogarciacaro
Copy link
Member

No worries @absolutejam! Actually I check GH issues much more often than chat channels (although other Fable users can sometimes help in the Gitter channel). Unfortunately, that error message seems to come from the F# compiler and not Fable itself (Fable calls F# compiler first to parse and type check the source code), so I'm not sure what could be the reason 🤔

Also, because we're a small item, we are currently focused on deliver Fable 3 so it's difficult to investigate an issue like this in Fable 2. Would it be possible to upgrade and check if the error is still happening in Fable 3? You can see an example of how to upgrade a Fable 2 app using Webpack here: MangelMaxime/fulma-demo#43

@absolutejam
Copy link
Author

absolutejam commented Nov 6, 2020

Thanks for getting back to me @alfonsogarciacaro. Ah I see; I didn't realise that was coming from the compiler.

Was hoping to jump to Fable 3 after watching F# eXchange, but didn't want to add something else into the mix. I have done that now, but sadly I've gotten the same issue, but dotnet build works just fine.

Is there some kind of mis-match between dotnet build and what's happening when it's run via. Fable? I'm running F# 5.0 RC1 but if it makes any difference, I have global.json as so:

{
    "sdk": {
        "version": "3.1.300"
    }
}
Console output
Unhandled exception. FSharp.Compiler.ErrorLogger+ReportedError: The exception has been reported. This internal exception should now be caught at an error recovery point on the stack. Original message: Invalid value)
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.Error[b](ErrorLogger x, Exception exn) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/ErrorLogger.fs:line 397
   at FSharp.Compiler.TypeRelations.destTopLambda(TcGlobals g, ImportMap amap, ValReprInfo topValInfo, Expr e, TType ty) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/TypeRelations.fs:line 263
   at FSharp.Compiler.TypeRelations.IteratedAdjustArityOfLambda(TcGlobals g, ImportMap amap, ValReprInfo topValInfo, Expr e) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/TypeRelations.fs:line 277
   at FSharp.Compiler.SourceCodeServices.FSharpImplementationFileContents.getBind(Binding bind) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/symbols/Exprs.fs:line 1254
   at <StartupCode$FSharp-Compiler-Service>[email protected](IEnumerable`1& next) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/symbols/Exprs.fs:line 1278
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/seqcore.fs:line 368
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at <StartupCode$FSharp-Compiler-Service>[email protected](IEnumerable`1& next) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/symbols/Exprs.fs:line 1283
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/seqcore.fs:line 368
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at <StartupCode$FSharp-Compiler-Service>[email protected](IEnumerable`1& next) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/symbols/Exprs.fs:line 1273
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/seqcore.fs:line 368
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at <StartupCode$FSharp-Compiler-Service>[email protected](IEnumerable`1& next) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/symbols/Exprs.fs:line 1283
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/seqcore.fs:line 368
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at <StartupCode$FSharp-Compiler-Service>[email protected](IEnumerable`1& next) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/symbols/Exprs.fs:line 1273
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/seqcore.fs:line 368
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at <StartupCode$FSharp-Compiler-Service>[email protected](IEnumerable`1& next) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/symbols/Exprs.fs:line 1273
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/seqcore.fs:line 368
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at <StartupCode$FSharp-Compiler-Service>[email protected](IEnumerable`1& next) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/symbols/Exprs.fs:line 1273
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/seqcore.fs:line 368
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at <StartupCode$FSharp-Compiler-Service>[email protected](IEnumerable`1& next) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/symbols/Exprs.fs:line 1283
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/seqcore.fs:line 368
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at Fable.Transforms.FSharp2Fable.Compiler.getRootModule(FSharpImplementationFileContents file) in /Users/alfonso/Documents/fable/src/Fable.Transforms/FSharp2Fable.fs:line 1169
   at [email protected](KeyValuePair`2 kv) in /Users/alfonso/Documents/fable/src/Fable.Transforms/State.fs:line 82
   at Microsoft.FSharp.Collections.Internal.IEnumerator.map@75.DoMoveNext(b& curr) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/seq.fs:line 78
   at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System.Collections.IEnumerator.MoveNext() in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/seq.fs:line 68
   at Microsoft.FSharp.Core.ExtraTopLevelOperators.dictRefType[TKey,T](IEnumerable`1 l) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs:line 165
   at Microsoft.FSharp.Core.ExtraTopLevelOperators.CreateDictionary[TKey,TValue](IEnumerable`1 keyValuePairs) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/fslib-extra-pervasives.fs:line 171
   at Fable.Transforms.State.Project..ctor(FSharpProjectOptions projectOptions, FSharpCheckProjectResults checkResults, FSharpOption`1 packages, FSharpOption`1 getPlugin, FSharpOption`1 optimize) in /Users/alfonso/Documents/fable/src/Fable.Transforms/State.fs:line 80
   at Fable.Cli.Main.ProjectParsed.Init(CliArgs cliArgs, ProjectCracked config, FSharpOption`1 checker) in /Users/alfonso/Documents/fable/src/Fable.Cli/Main.fs:line 305
   at [email protected](Unit unitVar) in /Users/alfonso/Documents/fable/src/Fable.Cli/Main.fs:line 399
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/async.fs:line 386
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/async.fs:line 105
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/async.fs:line 338
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInCurrentThread[a](CancellationToken cancellationToken, FSharpAsync`1 computation) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/async.fs:line 870
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/async.fs:line 878
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/async.fs:line 1142
   at Microsoft.FSharp.Core.ResultModule.Bind[T,TResult,TError](FSharpFunc`2 binder, FSharpResult`2 result) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/result.fs:line 15
   at Fable.Cli.Entry.Runner.Run(FSharpList`1 args, String rootDir, FSharpOption`1 runProc, FSharpOption`1 fsprojPath, FSharpOption`1 watch, FSharpOption`1 testInfo) in /Users/alfonso/Documents/fable/src/Fable.Cli/Entry.fs:line 87
   at [email protected](Tuple`2 _arg2) in /Users/alfonso/Documents/fable/src/Fable.Cli/Entry.fs:line 244
   at Microsoft.FSharp.Core.ResultModule.Bind[T,TResult,TError](FSharpFunc`2 binder, FSharpResult`2 result) in /Users/alfonso/dev/ncave_fsharp/src/fsharp/FSharp.Core/result.fs:line 15
   at Fable.Cli.Entry.main(String[] argv) in /Users/alfonso/Documents/fable/src/Fable.Cli/Entry.fs:line 204

@alfonsogarciacaro
Copy link
Member

In principle, latest Fable version contains the latest FCS (F# compiler services) code so it's equivalent to the F# 5 compiler, but it's still a netcoreapp3.1 should fine to run it with dotnet sdk 3.1.300.

Things you can try:

  • Use 3.0.0-nagareyama-rc-001 recently published
  • Reference FSharp.Core 5.0.0 in your project
  • Add LangVersion=preview property to your .fsproj (example)

If nothing of these works I would have to debug to spot where the error is happening, so it'd be nice to have access to the repo.

@absolutejam
Copy link
Author

absolutejam commented Nov 7, 2020

I tried the above, but no progress. So I moved the Client project out and started hacking away at it, but accidentally messed up the path to my Core project (where I have a lot of shared types, etc.), and noticed I didn't get this error.

So, I then tried transpiling Core with Fable and realised it was this throwing the error. After slowly chopping away references to .fs files, I found that it stops throwing when I remove reference to a file containing the following:

module RealmWeaver.Core.Infrastructure.EventCodec

open FsCodec

/// Uses the supplied codec to decode the supplied event record `x`
let tryDecode
        (codec: IEventCodec<_, _, _>)
        (streamName: StreamName)
        (event: ITimelineEvent<byte[]>) =

    match codec.TryDecode event with
    | None -> None
    | x -> x

Which has the type:

val tryDecode: 
   codec     : IEventCodec<'a,byte array,'b> ->
   streamName: StreamName ->
   event     : ITimelineEvent<byte array> 
            -> option<'a>

This actually compiles okay if I change it to:

let tryDecode<'a, 'b>
        (codec: IEventCodec<'a, byte array, 'b>)
        (streamName: StreamName)
        (event: ITimelineEvent<byte[]>) =

but ultimately, I don't even need this in my Client project, it's just a byproduct of including a reference to my Core project. Which I guess that ultimately reveals my bigger issue.


Moreover, I've noticed a load of errors regarding functions that cannot be resolved or functions that need to be inlined. If these are not going to be used in my frontend/don't need to be transpiled, is there a directive or something I can use to exclude them?

The problem is, this project (Core) is referenced by by backend, frontend and other apps, as it contains a load of core types and helper utilities, and I don't really want to split everything off even more if I have to.

...Or am I just sidestepping the issue by conditionally compiling/ignoring parts?

@alfonsogarciacaro
Copy link
Member

Thanks a lot for investigating so much @absolutejam! We have identified a problem in #2252 that may be related, can you please try updating to 3.0.0-nagareyama-rc-002? Running this should work:

dotnet tool update fable --version "3.0.0-nagareyama-*"

@absolutejam
Copy link
Author

absolutejam commented Nov 9, 2020

So ultimately, I went through some part of the referenced Core project and wrapped some module contents in #if !FABLE_COMPILER as they're not required in my frontend. This has resolved issues I had transpiling transitive modules.

However, I've now bumped into the issue that Fable can't process the FSharp.Control.AsyncSeq package (error FSHARP: The namespace 'Linq' is not defined.), which is a transitive dependency in my Core project.

Is there a way to skip this with Fable, since it's not actually referenced directly in my Client project?

@alfonsogarciacaro
Copy link
Member

Hmm, we could add System.Linq to the .NET references allowed by Fable, but we're trying to limit the number to reduce memory usage. If there are not so many files in the Core project used by Client, would it be possible to just include links to those files directly instead of the Core project reference? That way you can control the dependencies from the client project. I did try to run FSharp.Control.AsyncSeq tests with Fable 3 and it worked: fsprojects/FSharp.Control.AsyncSeq#121

@absolutejam
Copy link
Author

Totally understand; I was thinking more of how I can best sort this issue out at my end.

I've instead split out my Core into 2 projects and all is well.

Thanks for you help and continued work on this amazing project!

@alfonsogarciacaro
Copy link
Member

Awesome @absolutejam, great to hear you made it work! Thanks to you for your collaboration and your patience, please don't hesitate to reopen if you've any other question 👍

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