【问题标题】:"Could not find package" error when running javascript that uses elm运行使用 elm 的 javascript 时出现“找不到包”错误
【发布时间】:2018-04-14 00:41:11
【问题描述】:

我设置了使用 elm-static-html-lib 生成 html 的 javascript,这需要从我的 elm 代码中传入视图、模型和 json 解码器。

当我尝试使用节点运行 javascript 时,我收到以下错误消息:“找不到包 mdgriffith/style-elements。”

我设置 javascript 的方式几乎与 elm-static-html-lib 的 github 页面的第一个示例中的设置方式完全相同:https://github.com/eeue56/elm-static-html-lib

有人知道为什么会这样吗?

这似乎是我正在使用的方法的问题,因为当我切换到使用 Html.program 创建视图时,我没有收到任何依赖关系错误。而且我已经尝试删除 elm-stuff/ 并重新构建,但这并不能解决问题。

这里是JS代码:

const esh = require("./node_modules/elm-static-html-lib/dist/index.js");
const fs = require('fs');
const model = { name: "Noah", age : 24 };
//const model = require('./index-new.json'); //with path
const options = { model : model, decoder: "Main.decodeModel", alreadyRun: false };


function generateHtml() {
    esh.default(process.cwd(), "Main.view", options)
    .then((generatedHtml) => {
        fs.writeFileSync("output.html", generatedHtml);
    });
}

generateHtml();

还有我的 Main.elm 模块

module Main exposing (..)

import Html exposing (Html)
import Json.Decode exposing (..)
import Element exposing (..)
import Element.Attributes exposing (percent, width, spacing)
import Element.Events exposing (..)
import Style exposing (..)

-- MODEL


type alias Model =
    { age : Int
    , name : String
    }

type Style
    = None

type Variation
    = Selected

decodeModel : Json.Decode.Decoder Model
decodeModel =
    Json.Decode.map2 Model
        (Json.Decode.field "age" Json.Decode.int)
        (Json.Decode.field "name" Json.Decode.string)


-- VIEW


view : Model -> Element Style variation msg
view model =
  column None [] [text "Hello"]

stylesheet : StyleSheet Style Variation
stylesheet =
    Style.styleSheet
        [ style None [] ]

【问题讨论】:

    标签: javascript html json package elm


    【解决方案1】:

    我调查了 elm-static-html-lib 代码,发现它创建了一个名为 .elm-static-html 的目录,并根据当前项目创建了另一个 elm-package.json 并将其放入该目录中,这样该目录也有一个 elm-stuff 文件夹。并且由于某种原因,除了 elm-lang 下的包之外的任何包都不会安装,即使它们已列在 elm-package.json 中。在这一点上,我想我应该和库的创建者谈谈,因为他的代码似乎有问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-07
      • 2018-12-25
      • 1970-01-01
      • 1970-01-01
      • 2021-06-11
      相关资源
      最近更新 更多