1

I have been following the Elm tutorial on the website and I tried it on a Mac and it worked, but when I ported it to Linux, it gave me the following error:

- I cannot find module 'Widget'.

Module 'Main' is trying to import it.

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

This was the code which was being used:

main.elm

module Main exposing (..)

import Html exposing (Html)
import Html.App
import Widget


-- MODEL


type alias AppModel =
    { widgetModel : Widget.Model
    }


initialModel : AppModel
initialModel =
    { widgetModel = Widget.initialModel
    }


init : ( AppModel, Cmd Msg )
init =
    ( initialModel, Cmd.none )



-- MESSAGES


type Msg
    = WidgetMsg Widget.Msg



-- VIEW


view : AppModel -> Html Msg
view model =
    Html.div []
        [ Html.App.map WidgetMsg (Widget.view model.widgetModel)
        ]



-- UPDATE


update : Msg -> AppModel -> ( AppModel, Cmd Msg )
update message model =
    case message of
        WidgetMsg subMsg ->
            let
                ( updatedWidgetModel, widgetCmd ) =
                    Widget.update subMsg model.widgetModel
            in
                ( { model | widgetModel = updatedWidgetModel }, Cmd.map WidgetMsg widgetCmd )



-- SUBSCIPTIONS


subscriptions : AppModel -> Sub Msg
subscriptions model =
    Sub.none



-- APP


main : Program Never
main =
    Html.App.program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }

widget.elm

module Widget exposing (..)

import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)


-- MODEL


type alias Model =
    { count : Int
    }


initialModel : Model
initialModel =
    { count = 0
    }



-- MESSAGES


type Msg
    = Increase



-- VIEW


view : Model -> Html Msg
view model =
    div []
        [ div [] [ text (toString model.count) ]
        , button [ onClick Increase ] [ text "Click" ]
        ]



-- UPDATE


update : Msg -> Model -> ( Model, Cmd Msg )
update message model =
    case message of
        Increase ->
            ( { model | count = model.count + 1 }, Cmd.none )

Any tips on how to fix this?

DevNebulae
  • 4,566
  • 3
  • 16
  • 27
  • 2
    Did you try to rename to Widget.elm? (It may be the case sensitivity issue.) – Tosh Sep 28 '16 at 21:19
  • If your Elm source code is not in the same folder, go check `elm-package.json`, you should have that folder specified in `source-directories`, like [here](https://github.com/halfzebra/elm-examples/blob/master/examples/fractal-architecture/elm-package.json) – halfzebra Sep 29 '16 at 07:44

1 Answers1

3

Because Linux filesystems are case sensitive, you should name your Elm files with the same case as the module they declare.

So in your case:

Main module should be in "Main.elm".

Widget module should be in "Widget.elm".

ianmjones
  • 3,395
  • 1
  • 25
  • 26