在clojurescript 1.10.773中,当我使用webpack打包项目时无法从cljs.js中使用eval。我认为这是因为eval正在调用find-ns-obj,而它与:bundle :target不工作。这说得通,但即使选项映射中传递了:ns,此错误仍然发生。
从cljs.js中使用eval在clojurescript 1.10.741中曾经正常工作,即便:target设置为:bundle。这看起来是因为clojurescript的早期版本在编译器选项中设置*target*时从未设置。
我遇到的错误是
core.cljs:11642 Uncaught Error: find-ns-obj not supported for target bundle
at Object.cljs$core$find_ns_obj [as find_ns_obj] (core.cljs:11642)
at Function.cljs$core$IFn$_invoke$arity$1 (core.cljs:11660)
at cljs$core$create_ns (core.cljs:11657)
at Function.cljs$js$compile_str_STAR__$_compile_loop (js.cljs:918)
at Function.cljs$core$IFn$_invoke$arity$3 (core.cljs:3918)
at Function.cljs$core$IFn$_invoke$arity$2 (core.cljs:3913)
at Function.cljs$core$IFn$_invoke$arity$2 (core.cljs:3948)
at core.cljs:10831
at Function.cljs$core$IFn$_invoke$arity$1 (core.cljs:10826)
at Function.cljs$core$IFn$_invoke$arity$variadic (core.cljs:10831)
cljs$core$find_ns_obj @ core.cljs:11642
(anonymous) @ core.cljs:11660
cljs$core$create_ns @ core.cljs:11657
cljs$js$compile_str_STAR__$_compile_loop @ js.cljs:918
(anonymous) @ core.cljs:3918
(anonymous) @ core.cljs:3913
(anonymous) @ core.cljs:3948
(anonymous) @ core.cljs:10831
(anonymous) @ core.cljs:10826
(anonymous) @ core.cljs:10831
cljs$core$trampoline @ core.cljs:10817
cljs$js$compile_str_STAR_ @ js.cljs:910
(anonymous) @ js.cljs:1019
cljs$js$compile_str @ js.cljs:968
interactive_syntax$core$eval_str @ core.cljs:48
run @ core.cljs:351
callCallback @ react-dom.development.js:188
invokeGuardedCallbackDev @ react-dom.development.js:237
invokeGuardedCallback @ react-dom.development.js:292
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:306
executeDispatch @ react-dom.development.js:389
executeDispatchesInOrder @ react-dom.development.js:414
executeDispatchesAndRelease @ react-dom.development.js:3278
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:3287
forEachAccumulated @ react-dom.development.js:3259
runEventsInBatch @ react-dom.development.js:3304
runExtractedPluginEventsInBatch @ react-dom.development.js:3514
handleTopLevel @ react-dom.development.js:3558
batchedEventUpdates$1 @ react-dom.development.js:21871
batchedEventUpdates @ react-dom.development.js:795
dispatchEventForLegacyPluginEventSystem @ react-dom.development.js:3568
attemptToDispatchEvent @ react-dom.development.js:4267
dispatchEvent @ react-dom.development.js:4189
unstable_runWithPriority @ scheduler.development.js:653
runWithPriority$1 @ react-dom.development.js:11039
discreteUpdates$1 @ react-dom.development.js:21887
discreteUpdates @ react-dom.development.js:806
dispatchDiscreteEvent @ react-dom.development.js:4168
Show 8 more frames
react-dom.development.js:327 Uncaught Error: find-ns-obj not supported for target bundle
at Object.cljs$core$find_ns_obj [as find_ns_obj] (core.cljs:11642)
at Function.cljs$core$IFn$_invoke$arity$1 (core.cljs:11660)
at cljs$core$create_ns (core.cljs:11657)
at Function.cljs$js$compile_str_STAR__$_compile_loop (js.cljs:918)
at Function.cljs$core$IFn$_invoke$arity$3 (core.cljs:3918)
at Function.cljs$core$IFn$_invoke$arity$2 (core.cljs:3913)
at Function.cljs$core$IFn$_invoke$arity$2 (core.cljs:3948)
at core.cljs:10831
at Function.cljs$core$IFn$_invoke$arity$1 (core.cljs:10826)
at Function.cljs$core$IFn$_invoke$arity$variadic (core.cljs:10831)
任何对eval
、eval-str
、compile-str
等的调用都会发生。例如
(eval-str (empty-state) "(+ 1 2)" "UNTITLED" {:eval js-eval} println)
即使我提供了自己的:ns
,我也会得到这个错误。