"namespacing" and file/folders

Hello,
I am trying to apply “namespacing” to my app.

Inside ./src/Examples/RamdomDie.elm I have the example from https://guide.elm-lang.org/effects/random.html . The module starts with

module Examples.RandomDie exposing (main)

In index.html body I have
<script>var app = Elm.Examples.RandomDie.init({...

Browser console has error :
Uncaught TypeError: Cannot read property 'RandomDie' of undefined

Thoughts on what I have done wrong?

What is defined on the Elm variable? Try logging it to the console in your browser.

I just discovered my issue was with bad arguments on elm-live.

I was telling it to use src/*.elm, which was not globbing down into src/Examples, even though the elm-live output ends a startup with

 elm-live:
  Watching src/**/*.elm.

So, that’s confusing on elm-live.
Anyway, seems to be working now with this command

elm-live src/**/*.elm --open --start-page=index.html -- --output=main.js

Great, glad to hear it’s working. You might want to open an issue for elm-live, if that message isn’t accurate.

Since I’m the author of that log line in elm-live, I thought I’d chime in :slight_smile:

elm-live picks up the directories it’s going to watch from your elm.json. The log line correctly says that it’s going to watch for file changes recursively in src. But, you’re supposed to give it the name of your main module as the first argument, src/Examples/RandomDie.elm in your case. It’s very curious that it somehow works with src/**/*.elm instead.

So elm-live doesn’t support having multiple main modules?

Apparently it does. Just tried it with elm-live src/Main1.elm src/Main2.elm -- --output elm.js.

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