Compiled Elm environment expectations

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.

You don’t give much detail about the environment that didn’t work. Can you describe it like you did the others? I think you might get more answers that way.
As soon as you load the generated file it creates an Elm object on whatever scope it’s run from. In simple cases that’s the window. It could also be a module object in something like CommonJS.

Ah, sorry. The environment that it wasn’t working in was also a babel-compiled import call. I’m still trying to track down the precise difference between the environments.

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