I’m starting to use Elm at work (super excited!), but I ran across some issues surrounding environments that Elm code is imported within. Particularly, I’m trying to import the compiled JS code as an ES6 module and then mount it within a React component. All works fine if I require it from a script, use an import
call with babel support, or use elm-webpack-loader. But in another environment, importing the compiled JS causes an immediate failure since it seems to require a this
context, or else it errors. Hacking in a (this || {})
makes it load and mount just fine.
So I’m wondering what the assumptions are about environment for loading a compiled Elm file. I fully expect that the init
function shouldn’t work unless in a browser, but it’s surprising that the code can break on load within a normal JS context.