这是与https://dev.clojure.org/jira/browse/CLJS-1682相同的问题,因此可以通过参考问题中找到错误的复现步骤。
以下是不同 cljs 版本上不同错误的特定细节
在 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$niwi$$tmp$$greeter$$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
相同的错误。