elm-lang / elm-make

A build tool for Elm projects
BSD 3-Clause "New" or "Revised" License
175 stars 45 forks source link

make Elm variable available on `this` scope. #154

Open ryan-haskell opened 7 years ago

ryan-haskell commented 7 years ago

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.

process-bot commented 7 years ago

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.

ryan-haskell commented 7 years ago

Repo with issue: https://github.com/RyanNHG/first-electron-app

ryan-haskell commented 7 years ago

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:

Let me know what you think.