这是我的项目的elm-package.json
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"simonh1000/elm-charts": "3.1.0 <= v < 4.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}
elm-charts
导出一个称为Chart
的模块。
在我的ChartView.elm
中,我想导入 Chart
module Components.ChartView exposing ( .. )
import Chart as C exposing ( .. )
import Html exposing ( Html, div )
import Html.Attributes exposing ( id, class )
但是当榆树试图编译时,我会得到错误:
I cannot find module 'Chart'.
Module 'Components.ChartView' 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
如果我从项目目录中打开ELM REPL,我可以按预期导入图表:
jon@jon-Xubuntu-VB:~/elixir/eval$ elm repl
> import Chart
>
有什么想法,为什么我在编译时无法"找到图表"?
尽管在评论中解决了这一点,但还没有人在答案中写下这一点。ELM不会从嵌套目录中找到依赖项:您想与elm-package.json
(毗邻elm-stuff
目录)以相同的目录运行elm repl
。听起来您在应用程序的最高级别上错误地在web/elm/
目录中使用了elm-package.json
文件。