elm-make
elm-make copied to clipboard
make Elm variable available on `this` scope.
Heyo Evan
I was trying to use Elm in an Electron app and I ran into a weird error where the Elm
variable was not defined.
I followed the tutorial at https://guide.elm-lang.org/interop/javascript.html like a noob.
Changing the generated file from var Elm = {}
to this.Elm = {}
gave me access to the variable, and my problems were resolved.
Likely, I goofed something up, but it's possible I finally made a contribution to Elm, and "wrote my first line" of Haskell code.
I'll attach a link to the repo so you can easily replicate the error.
Thanks for the pull request! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
Repo with issue: https://github.com/RyanNHG/first-electron-app
A workaround is shown here: https://github.com/mdgriffith/elm-electron-todomvc/blob/master/index.html
Where the line window.Elm = require('./elm.js')
is used to make the Elm
object globally available.
Choose your own adventure:
- "Adding
this.Elm
toelm-make
!" - "Adding
window.Elm = require('./elm.js')
to the guide for people using electron!" - "Neither, you're drunk Ryan, go home!"
Let me know what you think.