Elm 0.19 Single Page App with Capacitor

I would love to use one code base for an app I’m creating. It needs to run on both web and native mobile (for push notifications).

I’ve enjoyed the routing features introduced with Elm 0.19 and Capacitor seems to be a simple solution for adding native platforms to a project. For those interested, Will Strinz wrote an excellent introduction for using Elm with Capacitor here.

I created the app for web first and then added in Capacitor. As the app was booting in the iOS simulator it errored out because Capacitor attempts to serve the app in iOS from capacitor://localhost while elm/url accepts only http or https as valid schemes.

This issue addresses the problem. I am so close on this that I don’t want to abandon Capacitor. And I don’t want to give up Elm routing either. My thought is to download elm/url and elm/browser locally, make a small update to elm/url so that it supports the capacitor scheme and rebuild both locally. However, I encounter this error attempting to compile elm/browser:

elm make src/Browser.elm
Dependencies loaded from local cache.
Dependencies ready!                
elm: Cannot find kernel import of: Browser.Dom
CallStack (from HasCallStack):
  error, called at compiler/src/Elm/Kernel.hs:99:9 in main:Elm.Kernel

This makes me wonder if it is even possible to compile core Elm packages locally :thinking:

Ultimately I have two questions:

  1. Has anyone been successful running Elm 0.19 with elm/browser's routing in Capacitor?
  2. Is it possible to build core Elm components locally?

I would very much like to know how either or both of these can be achieved.

Thank you very much for your time!

5 Likes

You cannot have Kernel code in your own application, so some core packages cannot be compiled locally, normally.

You’ve basically got three solutions:

  1. use the hackish way of patching your local cached copy in $HOME/.elm while you wait for the updated package to be published. This is documented in some discussions here, it’s hackish, doesn’t scale if you want to collaborate with someone else, but works for this kind of “small edit, while waiting a patch” scenarios
  2. recompile the Elm compiler removing the kernel code restriction
  3. monkey patch the js object that is used by elm-url so that it lies
1 Like

Thank you very much for the reply @miniBill!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.