javascript - 运行使用 elm 的 javascript 时出现 "Could not find package"错误

标签 javascript html json package elm

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

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

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

有谁知道为什么会这样?

这似乎是我使用的方法的问题,因为当我切换到使用 Html.program 来创建 View 时,我没有收到任何依赖项错误。我试过删除 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 [] ]

最佳答案

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

关于javascript - 运行使用 elm 的 javascript 时出现 "Could not find package"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47059228/

相关文章:

javascript - setTimeout 在 for 循环内的 promise

javascript - 如何检查一个 JSON 对象是否存在于另一个对象中

json.loads(request.body) 给出 "No JSON object could be decoded"错误 (Django)

javascript - JavaScript 中的 JSON ISO8601 解析

javascript - 视频在 Internet Explorer 上中止加载

javascript - 需要将一些值传递到 JavaScript 中的数组中,但很困难

javascript - 如何从 forEach 函数聚合 json 对象数组?

html - 如何在 HTML 中设置按钮的大小

html - 在 CSS 中突出显示右边距较短的文本

javascript - 在模式中滚动