尝试导入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是文件和模块的名称,取自此处,似乎工作正常,但不适用于我。
我正在使用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": {}
}
}
您尝试使用的代码已过时。据我所知,它Date
已从core
Elm 0.19中删除,没有直接替换,也没有包含完全相同功能的间接替换。elm/time
旨在成为正式接班人Date
和Time
,但它没有提供日期/时间字符串解析这是什么您这里需要。
旧的Date.fromString
只是JavaScript解析API的一个薄包装,因此不是非常一致或定义明确。因此,为什么要删除它。在Elm 0.19中,您必须使用提供更特定功能的第三方软件包,例如elm-iso8601-date-strings。
如果收到的是ISO 8601字符串,则应该可以替换parseTime
为:
import Iso8601
import Time
parseTime : String -> Time.Posix
parseTime string =
Iso8601.toTime string
|> Result.withDefault (Time.millisToPosix 0)
但是,如果收到的不是ISO 8601格式,则需要找到另一个解析该特定格式的程序包。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句