我设置了 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/