当尝试导入Date模块并在一个简单的Elm文件中使用它时,我得到了以下错误:
-- UNKNOWN IMPORT ---------------------------- app/javascript/CountdownTimer.elm
The CountdownTimer module has a bad import:
import Date
I cannot find that module! Is there a typo in the module name?
The "source-directories" field of your elm.json tells me to only look in the src
directory, but it is not there. Maybe it is in a package that is not installed
yet?CountdownTimer是文件和模块的名称,取自here,它似乎工作得很好,但对我来说并非如此。
我使用的是Elm 0.19.0和Rails 6.0.0beta1,这似乎不是一个限制,因为如果我在任何地方输入Elm REPL,并尝试导入日期,我会遇到相同的错误:
> import Date
-- UNKNOWN IMPORT ---------------------------------------------------------- elm
The Elm_Repl module has a bad import:
import Date
I cannot find that module! Is there a typo in the module name?
When creating a package, all modules must live in the src/ directory.我的elm.json文件如下所示:
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/html": "1.0.0",
"elm/time": "1.0.0",
"elm/json": "1.1.2",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
},
"indirect": {
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}发布于 2019-01-21 20:03:46
您尝试使用的代码已过时。据我所知,在ELM0.19中,Date被从core中删除,没有直接替换,也没有覆盖完全相同功能的间接替换。elm/time旨在作为Date和Time的官方继承者,但它不提供您在这里需要的日期/时间字符串解析。
旧的Date.fromString只是JavaScript解析API的一个薄薄的包装器,因此不是非常一致或定义良好的。这就是它被移除的原因。在Elm 0.19中,您必须使用提供更具体功能的第三方包,比如elm-iso8601-date-strings。
如果您收到的是ISO8601字符串,您应该能够将parseTime替换为:
import Iso8601
import Time
parseTime : String -> Time.Posix
parseTime string =
Iso8601.toTime string
|> Result.withDefault (Time.millisToPosix 0)但是,如果您收到的不是ISO 8601格式,则需要找到另一个解析该特定格式的包。
https://stackoverflow.com/questions/54289034
复制相似问题