2024 Clojure状态调查中分享您的想法!

欢迎!请查看关于页面了解更多有关如何使用本网站的信息。

0
ClojureScript

这是与https://dev.clojure.org/jira/browse/CLJS-1682相同的问题,所以所有用于复现错误的指令都可以在引用的问题中找到。

以下是不同ClojureScript版本中不同错误的具体细节

使用cljs==1.9.845时,两种情况下编译都成功终止(在build.clj中的:foreign-libs以及在deps.cljs中),但执行生成的JavaScript时会出现异常

`
$ node out/main.js
out/src/vendor/greeter.js:3
exports.sayHello = function(name) {

             ^

TypeError: Cannot set property 'sayHello' of undefined

at out/src/vendor/greeter.js:3:18
at ContextifyScript.Script.runInThisContext (vm.js:50:33)
at Object.runInThisContext (vm.js:139:38)
at Object.nodeGlobalRequire (/home/niwi/tmp/greeter/out/goog/bootstrap/nodejs.js:85:8)
at Object.cljs$core$load_file [as load_file] (/home/niwi/tmp/greeter/out/cljs/core.js:341:13)
at Object.<anonymous> (/home/niwi/tmp/greeter/out/testapp/core.js:5:11)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)

`

使用cljs==1.9.908时,两种情况下编译都成功终止,但在执行生成的JavaScript时会出现其他异常

`
$ node out/main.js
/home/niwi/tmp/greeter/out/testapp/core.js:28
return cljs.core.println.call(null,module$src$vendor$greeter.sayHello("Ciri"));

                                                         ^

TypeError: module$src$vendor$greeter.sayHello is not a function

at Function.testapp.core._main.cljs$core$IFn$_invoke$arity$variadic (/home/niwi/tmp/greeter/out/testapp/core.js:28:62)
at testapp$core$_main (/home/niwi/tmp/greeter/out/testapp/core.js:24:27)
at Object.cljs$core$apply_to [as apply_to] (/home/niwi/tmp/greeter/out/cljs/core.js:12793:81)
at Function.cljs.core.apply.cljs$core$IFn$_invoke$arity$2 (/home/niwi/tmp/greeter/out/cljs/core.js:13237:18)
at cljs$core$apply (/home/niwi/tmp/greeter/out/cljs/core.js:13195:24)
at Object.<anonymous> (/home/niwi/tmp/greeter/out/DF0FC10.js:9:17)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)

`

而已使用cljs==1.9.946,在build.clj文件中使用:foreign-libs时,会引发以下错误

`
$ java -cp cljs.jar:src clojure.main build.clj
module.js:529

throw err;
^

Error: Cannot find module '@cljs-oss/module-deps'

at Function.Module._resolveFilename (module.js:527:15)
at Function.Module._load (module.js:476:23)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at [eval]:3:13
at ContextifyScript.Script.runInThisContext (vm.js:50:33)
at Object.runInThisContext (vm.js:139:38)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:624:30)
at evalScript (bootstrap_node.js:462:27)

正在复制文件:/home/niwi/tmp/greeter/src/vendor/greeter.js 到 out/src/vendor/greeter.js
正在复制jar:/file:/home/niwi/tmp/greeter/cljs.jar!/cljs/core.cljs 到 out/cljs/core.cljs
正在读取jar的缓存文件:/file:/home/niwi/tmp/greeter/cljs.jar!/cljs/core.cljs
正在编译out/cljs/core.cljs
[...]
`

无论错误如何,编译都会继续并终止,生成的JavaScript会引发以下错误(与使用cljs==1.9.908时的错误非常相似)

`
$ node out/main.js
/home/niwi/tmp/greeter/out/testapp/core.js:28
return cljs.core.println.call(null,module$home$niwiagner$src$vendor$greeter.sayHello("Ciri"));

                                                                               ^

TypeError: module$home$niwi$tmp$greeter$src$vendor$greeter.sayHello is not a function

at Function.testapp.core._main.cljs$core$IFn$_invoke$arity$variadic (/home/niwi/tmp/greeter/out/testapp/core.js:28:84)
at testapp$core$_main (/home/niwi/tmp/greeter/out/testapp/core.js:24:27)
at Object.cljs$core$apply_to [as apply_to] (/home/niwi/tmp/greeter/out/cljs/core.js:12785:81)
at Function.cljs.core.apply.cljs$core$IFn$_invoke$arity$2 (/home/niwi/tmp/greeter/out/cljs/core.js:13229:18)
at cljs$core$apply (/home/niwi/tmp/greeter/out/cljs/core.js:13187:24)
at Object.<anonymous> (/home/niwi/tmp/greeter/out/AEF573C.js:10:17)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)

`

deps.cljs文件中设置:foreign-lib时,编译没有错误终止,但生成的JavaScript会引发与使用cljs==1.9.845时相同的错误。

2个回答

0

评论由:bobby发表

我可以确认此问题在版本1.10.339中仍然存在。我必须使用以下命令来使用:foreign-libs:module-type :es6npm install --save @cljs-oss/module-deps。我没有设置:npm-deps,所以这似乎是一个不直观的额外步骤。

0
参考:[https://clojure.atlassian.net/browse/CLJS-2399](https://clojure.atlassian.net/browse/CLJS-2399)(由alex+import报告)
...