2016-09-28 36 views
1

我一直在關注網站上的榆樹教程,我試了一下在Mac上和它的工作,但是當我將它移植到Linux,它給了我下面的錯誤:我找不到模塊「窗口小部件」

- 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 

這是將其正在使用的代碼:

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) 

有關如何解決這個問題的任何提示?

+2

您是否嘗試重命名爲Widget.elm? (這可能是區分大小寫的問題。) – Tosh

+0

如果您的Elm源代碼不在同一個文件夾中,請檢查'elm-package.json',您應該在'source-directories'中指定該文件夾,如[here] (https://github.com/halfzebra/elm-examples/blob/master/examples/fractal-architecture/elm-package.json) – halfzebra

回答

3

由於Linux文件系統區分大小寫,因此您應該將您的Elm文件命名爲與它們聲明的模塊相同的大小寫。

所以你的情況:

Main模塊應在 「Main.elm」。

Widget模塊應該在「Widget.elm」中。

相關問題