How do I get elm-make to find Native modules?

724 views
Skip to first unread message

Paul Chiusano

unread,
Feb 2, 2015, 5:46:32 PM2/2/15
to elm-d...@googlegroups.com
I am trying to write a library that uses some native JS, but am getting an error 'could not find module Native.MyModuleName' when trying to compile using elm-make. I've cloned the directory structure and stub of the native code from Max New's lazy package (thanks Max!): https://github.com/maxsnew/lazy/blob/master/src/Native/Lazy.js

I'm guessing I'm just doing something silly. Any help would be greatly appreciated!

Here's what I'm doing:

    $ elm-make src/Messages.elm --output=messages.html
    Error when searching for modules imported by module 'Messages':
        Could not find module 'Native.Messages'

    Potential problems could be:
      * Misspelled the module name
      * Need to add a source directory or new dependency to elm-package.json

Hmm, ok. Here's my elm-package.json:

    {
        "version": "1.0.0",
        "summary": "w00t",
        "repository": "https://github.com/USER/PROJECT.git",
        "license": "MIT",
        "source-directories": [
            "src"
        ],
        "exposed-modules": ["Messages"],
        "dependencies": {
            "elm-lang/core" : "1.0.0 <= v < 2.0.0",
            "Dandandan/Easing" : "1.0.1 <= v < 2.0.0",  
            "maxsnew/lazy" : "1.0.0 <= v < 2.0.0"
        }
    }

And here's my directory structure:

    src/
      Native/
        Messages.js
      Messages.elm

And here's the relevant content from Messages.elm:

    module Messages where

    import Native.Messages

    -- some stuff


And Messages.js: 

    Elm.Native.Messages = {};
    Elm.Native.Messages.make = function(localRuntime) {

        localRuntime.Native = localRuntime.Native || {};
        localRuntime.Native.Messages = localRuntime.Native.Messages || {};
        if (localRuntime.Native.Messages.values) {
            return localRuntime.Native.Messages.values;
        }

        function blah(oog) {
          // some stuff
        }

        return localRuntime.Native.Messages.values = {
            blah: blah
        };
    };

Could anyone tell me what I'm doing wrong?

Paul :)

Hassan Hayat

unread,
Feb 2, 2015, 5:59:15 PM2/2/15
to elm-d...@googlegroups.com
1) You have to add : 

"native-modules" : true,

to your elm-package.json file or else it wont work.

Here's an example from one of my libraries

{
   "version": "1.0.0",
   "summary": "For-loops and While-loops in Elm",
   "repository": "https://github.com/TheSeamau5/elm-loop.git",
   "license": "BSD3",
   "source-directories": [
       "src"
   ],
   "exposed-modules": [
     "Loop"
   ],
   "native-modules" : true,
   "dependencies": {
       "elm-lang/core": "1.1.0 <= v < 2.0.0"
   }
}

Paul Chiusano

unread,
Feb 2, 2015, 6:07:11 PM2/2/15
to elm-d...@googlegroups.com
Sweet! Thank you. I'm not sure how I missed that, but works now.

Paul :)

--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/ndVt0vcbcYc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages