我正试图在一个寓言式的elmish模板项目中使用寓言的powerpack。在编译期间有一个警告:
warning FABLE: Nested option in option won't work at runtime
编译后的代码(在测试中使用fable powerpack代码)也不起作用。
代码:
let openCursor(index: Browser.IDBIndex, keyCursor: bool, range: Browser.IDBKeyRange option, direction: DBCursorDirection option, step: uint32 option) =
let range = defaultArg range Unchecked.defaultof<Browser.IDBKeyRange>
let direction = (defaultArg direction DBCursorDirection.Default).ToString()
let step = defaultArg step 1u
let request =
match keyCursor with
| false -> index.openCursor(range, direction) //warning here
| true -> index.openKeyCursor(range, direction)//warning here
转换为:
function openCursor(index, keyCursor, range, direction, step) {
var range_1 = range != null ? range : null;
var direction_1 = Object(__WEBPACK_IMPORTED_MODULE_3__nuget_packages_fable_core_1_2_4_fable_core_Util__["y"/* toString */
])(direction != null ? direction : DBCursorDirection.Default);
var step_1 = step != null ? step : 1;
var request = keyCursor ? index.openKeyCursor(Object(__WEBPACK_IMPORTED_MODULE_3__nuget_packages_fable_core_1_2_4_fable_core_Util__["x"/* some */
])(range_1), direction_1) : index.openCursor(Object(__WEBPACK_IMPORTED_MODULE_3__nuget_packages_fable_core_1_2_4_fable_core_Util__["x"/* some */
])(range_1), direction_1);
range_1为空,没问题,但
Object(__WEBPACK_IMPORTED_MODULE_3__nuget_packages_fable_core_1_2_4_fable_core_Util__["x"/* some */])(null)
返回{}而不是undefined,如果它返回undefined(或null?)那么就没问题了
克隆了powerpack项目并且工作正常,openCursor被翻译为:
function openCursor(index, keyCursor, range, direction, step) {
var range_1 = range != null ? range : null;
var direction_1 = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__nuget_packages_fable_core_1_2_0_beta_003_fable_core_Util__["f" /* toString */])(direction != null ? direction : DBCursorDirection.Default);
var step_1 = step != null ? step : 1;
var request = keyCursor ? index.openKeyCursor(range_1, direction_1) : index.openCursor(range_1, direction_1);
我可以看到它使用了一个不同的dotnet-fable(1.2.4来自fable elmish模板)所以将paket.lock更改为降级(1.2.0-beta-005来自fable-powerpack)并进行了一次dotnet恢复。 / p>
现在它根本不会编译错误(可能反应无法与powerpack使用的寓言版本一起使用):
/home/harm/.nuget/packages/fable.react/1.2.1/fable/Fable.Helpers.React.fs中的错误 /home/harm/.nuget/packages/fable.react/1.2.1/fable/Fable.Helpers.React.fs(588,53):( 588,62)错误FSHARP:未定义类型'ParamList'。 @ ./src/App.fs 5:0-107 @ ./src/sale.fsproj @ multi(webpack)-dev-server / client?http://localhost:8080 webpack / hot / dev-server ./src/sale.fsproj
克隆Fable compiler并构建它(不会生成nuget包,但会生成一些包含二进制文件的文件夹)。
在与构建链接的寓言电源包中:
ln -s ../Fable/build/fable ./fable
然后尝试构建power pack indexeddb(已更改测试/ Main.fs和Tests.fsproj以使用indexeddb的Program.fs)
dotnet ./fable/dotnet-fable.dll yarn-run pretest
果然这也不起作用:
> ./src/IndexedDB.fs中的错误 找不到模块:错误:无法解析'/ home / harm /中的'../../../.nuget/packages/fable.core/1.2.0-beta-003/fable-core/Option'开发/寓言-动力组/ src”中 @ ./src/IndexedDB.fs 9:0-102 @ ./tests/Program.fs @ ./tests/Main.fs @ ./tests/Tests.fsproj > ./src/PromiseSeq/Module.fs中的错误 找不到模块:错误:无法解析'/ home中的'../../../../.nuget/packages/fable.core/1.2.0-beta-003/fable-core/Option' /伤害的/ dev /寓言的PowerPack / src目录/ PromiseSeq” @ ./src/PromiseSeq/Module.fs 10:0-99 @ ./src/PromiseSeq/Extensions.fs @ ./tests/Program.fs @ ./tests/Main.fs @ ./tests/Tests.fsproj
目录~/.nuget/packages/fable.core/1.2.0-beta-003/fable-core/
存在,但我猜相对路径不正确。另外它从1.2.0开始,Fable版本的fable核心是版本1.3.0-beta-002
所以即使我因为某种原因使用了dotnet-fable版本1.3.0-beta-002
它也没有使用寓言核心由构建生成的编译。
使用paket.lock是否支持dotnet-fable?如果是这样,那么为什么不构建Fable提供nuget包,因为如果你不想花费接下来的3天来摆弄复制/链接文件和弄乱packet.lock,就必须安装它。
寓言编译器缺少有关如何实际使用它的一些说明。我可以编译它,但因为它没有生成nuget,所以无法安装它。直接运行二进制文件似乎也不起作用。
有没有办法使用寓言编译器git repo中最新版本生成的二进制文件构建项目,并使用它来转换项目?
我尝试通过更改paket.dependencies来安装新版本:
source https://www.nuget.org/api/v2
nuget Fable.Compiler 1.3.0-beta-002 beta
nuget FSharp.Core
nuget Fable.Core prerelease
nuget Fable.Import.Browser
clitool dotnet-fable 1.3.0-beta-002
group Build
framework: net46
source https://nuget.org/api/v2
nuget FSharp.Core redirects:force, content:none
nuget FAKE
然后尝试了以下命令
dotnet restore
这似乎没有做任何尝试:
mono .paket/paket.exe update
将paket.lock更改为:
dotnet-fable (1.3.0-beta-002) - clitool: true
...
Fable.Compiler (1.3.0-beta-002)
...
Fable.Core (1.3.0-beta-002)
但仍然是dotnet寓言不会运行1.3.0:
[harm@localhost fable-powerpack]$ dotnet fable yarn-run pretest
Fable (1.2.0-beta-005) daemon started on port 61225
来源仍然是用寓言的核心1.2.0编译的,所以只是为了它的地狱再次尝试了以下命令:
dotnet restore
现在尝试转换:
[harm@localhost fable-powerpack]$ dotnet fable yarn-run pretest
Fable (1.3.0-beta-002) daemon started on port 61225
这导致警告:
WARNING in ./src/IndexedDB.fs
157:30-34 "export 'Some' was not found in '../../../.nuget/packages/fable.core/1.2.0-beta-003/fable-core/Util'
代码不起作用:
TypeError: __WEBPACK_IMPORTED_MODULE_1__nuget_packages_fable_core_1_2_0_beta_003_fable_core_Util__.Some is not a constructor at openCursor (file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:3527:191) at IDBObjectStore_openCursorAsync (file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:3668:10) at file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:4685:123 at file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:4642:28 at Object.then (file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:1936:22) at IDBOpenDBRequest.request.onsuccess (file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:3803:36)
message
:
"__WEBPACK_IMPORTED_MODULE_1__nuget_packages_fable_core_1_2_0_beta_003_fable_core_Util__.Some is not a constructor"
stack
:
"TypeError: __WEBPACK_IMPORTED_MODULE_1__nuget_packages_fable_core_1_2_0_beta_003_fable_core_Util__.Some is not a constructor↵ at openCursor (file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:3527:191)↵ at IDBObjectStore_openCursorAsync (file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:3668:10)↵ at file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:4685:123↵ at file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:4642:28↵ at Object.then (file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:1936:22)↵ at IDBOpenDBRequest.request.onsuccess (file:///home/harm/dev/fable-powerpack/build/tests.bundle.js:3803:36)"
__proto__
:
Error
仍然顽固地尝试寓言核心1.2.0
所以寻找这个版本:
[harm@localhost fable-powerpack]$ grep -rl "1.2.0.beta.003"
obj/fsac.cache
tests/obj/project.assets.json
tests/obj/fsac.cache
build/tests.bundle.js
tests/obj/project.assets.json
有超过5400行,所以不会摆弄那一行。
所以尝试了以下内容:
[harm@localhost fable-powerpack]$ cd tests/
[harm@localhost tests]$ mono ../.paket/paket.exe update
[harm@localhost tests]$ dotnet restore
这似乎照顾到了这一点:
[harm@localhost fable-powerpack]$ grep -rl "1.2.0.beta.003"
obj/fsac.cache
tests/obj/fsac.cache
build/tests.bundle.js
...
这似乎是使用最新的寓言,但最新的寓言编译:
function openCursor(index, keyCursor, range, direction, step) {
var range_1 = range != null ? range : null;
var direction_1 = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__nuget_packages_fable_core_1_3_0_beta_002_fable_core_Util__["g" /* toString */])(direction != null ? direction : DBCursorDirection.Default);
var step_1 = step != null ? step : 1;
var request = keyCursor ? index.openKeyCursor(new __WEBPACK_IMPORTED_MODULE_1__nuget_packages_fable_core_1_3_0_beta_002_fable_core_Util__["f" /* Some */](range_1), direction_1) : index.openCursor(new __WEBPACK_IMPORTED_MODULE_1__nuget_packages_fable_core_1_3_0_beta_002_fable_core_Util__["f" /* Some */](range_1), direction_1);
与1.2.4相同,因此运行脚本时出现错误。
答案 0 :(得分:0)
编译JavaScript中的嵌套选项警告和错误是solved。
安装可以执行的paket依赖项(从paket.dependencies获取版本并重新创建paket.lock):
mono .paket/paket.exe update
dotnet restore
如果paket update为您提供超时异常,您可以在paket更新之前尝试此命令:
export PAKET_RESOLVER_TASK_TIMEOUT=-1
在这种情况下,您需要在test direcectory
中再次运行dotnet restore