这是与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
时相同的错误。