SAFE-template icon indicating copy to clipboard operation
SAFE-template copied to clipboard

Webpack error after upgrading to V3

Open Alkasai opened this issue 3 years ago • 5 comments

I'm trying to upgrade my project to V3 and after following all the steps here https://safe-stack.github.io/docs/recipes/upgrading/v2-to-v3/ Now I'm trying to run npm run-script build, but I get a following error:

ERROR in ./src/Client/output/App.js 261:74
Module parse failed: Unexpected token (261:74)
File was processed with these loaders:
 * ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
|         const current = current_2;
|         window.Elmish_HMR_Count = ((window.Elmish_HMR_Count == null) ? 0 : (window.Elmish_HMR_Count + 1));
>         Internal_tryRestoreState(hmrState, (current.tag === 1) ? (((import.meta.webpackHot).accept(), (import.meta.webpackHot).data)) : ((current.tag === 2) ? (((module.hot).accept(), (module.hot).data)) : ((import.meta.hot.accept(), import.meta.hot.data))));
|     }
|     const map_2 = (tupledArg_4) => [tupledArg_4[0], Cmd_map((arg0_2) => (new Msg$1(0, arg0_2)), tupledArg_4[1])];

How do I debug? I'm not too familiar with webpack so no idea what is going on under the hood. And for the reference running the same command on a vanilla SAFE project works just fine on the same machine.

Alkasai avatar Nov 23 '21 01:11 Alkasai

The line it's pointing to is to do with HMR, so I'd try disabling HMR by commenting out the open Elmish.HMR line in #if DEBUG and/or doing a release build to see if it makes a difference.

Are you able to provide a repro?

olivercoad avatar Nov 25 '21 05:11 olivercoad

It's probably this https://github.com/elmish/hmr/issues/35. You can pin Fable.Elmish.HMR to version 4.1 in your paket.dependencies, or following step 6 in the upgrade recipe overwrite the paket.lock file and add back any extra nuget packages.

olivercoad avatar Nov 25 '21 06:11 olivercoad

Ah I must've missed that step. Makes total sense! 🤦 So this got resolved by:

  • copying over the paket.lock from a vanilla SAFE project
  • running dotnet paket install

Thank you!

There are some server errors now, I'll go dig into them.

Alkasai avatar Nov 25 '21 13:11 Alkasai

cc @Akash-Mair @Ryan-Palmer-CIT - might need to update the recipe here?

isaacabraham avatar Nov 25 '21 19:11 isaacabraham

I might be misunderstanding the above, but far as I can tell pinning Fable.Elmish.HMR to version 4.1.0 is the only solution under which the build survives a paket update call. Adding that pin to the template's paket.dependencies file might be a good idea for now? OTOH, with all the other packages I've had to pin to old versions recently (due to .NET 6 versioning), I'm holding out hope that a .NET 6-compatible SAFE Stack upgrade will magically obviate this problem as well. :-)

geysernrd avatar Apr 18 '22 21:04 geysernrd

Based on https://github.com/SAFE-Stack/SAFE-template/issues/483#issuecomment-979238079 it looks to me like this is resolved and the recipe is correct, so I'll close the issue.

theprash avatar Sep 01 '22 16:09 theprash