我推测以下内容无法工作,因为在REPL中require时没有涉及Closure。
{code:title=co.edn}
{:output-dir "out"
:output-to "out/main.js"
:optimizations :none
:install-deps true
:npm-deps {:react "15.6.1"
:react-dom "15.6.1"}}
{code:title=src/example/core.cljs}
(ns example.core
(:require [react :refer [createElement]]
["react-dom/server" :as ReactDOMServer :refer [renderToString]]))
(js/console.log (renderToString (createElement "div" nil "Hello World!")))
这可以正常工作
clj -m cljs.main -co co.edn -c example.core -r
在浏览器控制台输出此内容
[Log] <div data-reactroot="" data-reactid="1" data-react-checksum="1309021079">Hello World!</div> (core.js, line 6)
但如果您从头开始(没有 {{out}}, {{node_modules}}, {{package.json}} 和 {{package-lock.json}})并执行
clj -m cljs.main -co co.edn -r
然后按照REPL中的以下内容进行操作:
(require 'example.core)
REPL控制台没有显示错误,但JavaScript控制台显示了大量的错误。
我认为为了满足这个问题的需求,这可能“ somehow”完成,或者可能检测到问题并抛出一个{{ex-info}}异常,告知用户这种方式无法工作。
以下是记录的错误
[Error] ReferenceError: Can't find variable: process
Global Code (warning.js:4)
[Error] ReferenceError: Can't find variable: process
Global Code (canDefineProperty.js:2:170)
[Error] ReferenceError: Can't find variable: process
Global Code (emptyObject.js:2:153)
[Error] ReferenceError: Can't find variable: process
Global Code (invariant.js:4:192)
[Error] ReferenceError: Can't find variable: process
Global Code (lowPriorityWarning.js:3)
[Error] ReferenceError: Can't find variable: process
Global Code (ReactBaseClasses.js:16)
[Error] ReferenceError: Can't find variable: process
Global Code (ReactPropTypeLocationNames.js:2:185)
[Error] ReferenceError: Can't find variable: process
Global Code (ReactDOMFactories.js:5)
[Error] ReferenceError: Can't find variable: process
Global Code (checkPropTypes.js:10)
[Error] ReferenceError: Can't find variable: process
createChainableTypeChecker (factoryWithTypeCheckers.js:12:305)
createPrimitiveTypeChecker (factoryWithTypeCheckers.js:17:102)
(anonymous function) (factoryWithTypeCheckers.js:10:535)
(anonymous function) (factory.js:3:441)
Global Code (ReactPropTypes.js:5:149)
[Error] ReferenceError: Can't find variable: process
Global Code (factory.js:34:317)
[Error] ReferenceError: Can't find variable: process
Global Code (React.js:18)
[Error] ReferenceError: Can't find variable: process
Global Code (EventPluginRegistry.js:16:218)
[Error] ReferenceError: Can't find variable: process
Global Code (ReactErrorUtils.js:5)
[Error] ReferenceError: Can't find variable: process
Global Code (EventPluginUtils.js:12)
[Error] TypeError: undefined is not an object (evaluating 'module$private$$tmp$$island$$node_modules$$react_dom$$lib$$EventPluginRegistry["default"].injectEventPluginOrder')
Global Code (EventPluginHub.js:16:199)
[Error] TypeError: undefined is not an object (evaluating 'module$private$$tmp$$island$$node_modules$$react_dom$$lib$$EventPluginHub["default"].getListener')
Global Code (EventPropagators.js:9:167)
[Error] ReferenceError: Can't find variable: process
Global Code (SyntheticEvent.js:18)
[Error] TypeError: undefined is not a function (near '...module$private$$tmp$$island$$node_modules$$react_dom$$lib$$SyntheticEvent["default"].augmentClass...')
全局代码(SyntheticCompositionEvent.js:4:393)
[Error] TypeError: undefined is not a function (near '...module$private$$tmp$$island$$node_modules$$react_dom$$lib$$SyntheticEvent["default"].augmentClass...')
全局代码(SyntheticInputEvent.js:4:203)
[Error] ReferenceError: Can't find variable: process
全局代码(DOMProperty.js:14:471)
[错误] TypeError: 未定义不是对象(在评估'module$private$tmp$island$node_modules$react_dom$lib$DOMProperty["default"].ID_ATTRIBUTE_NAME'时出错)
全局代码(ReactDOMComponentTree.js:7:516)
[Error] ReferenceError: Can't find variable: process
全局代码(ReactInvalidSetStateWarningHook.js:4)
[Error] ReferenceError: Can't find variable: process
全局代码(ReactInstrumentation.js:4)
[Error] TypeError: undefined is not a function (near '...module$private$$tmp$$island$$node_modules$$react_dom$$lib$$SyntheticEvent["default"].augmentClass...')
全局代码(SyntheticUIEvent.js:7:93)
[错误] TypeError: 未定义不是一个函数(在'...module$private/tmp$island/node_modules/react_dom/lib/SyntheticUIEvent["default"].augmentClass...'附近)
全局代码(SyntheticMouseEvent.js:9:95)
[错误] TypeError: 未定义不是对象(在评估'module$privatetmp$island$node_modules$react_dom/lib$DOMProperty["default"].injection'时出错)
全局代码(HTMLDOMPropertyConfig.js:3:425)
[Error] ReferenceError: Can't find variable: process
全局代码(DOMChildrenOperations.js:21)
[错误] TypeError: 未定义不是对象(在评估'module$private(tmp$island$node_modules$react_dom/lib$DOMChildrenOperations["default"].dangerouslyReplaceNodeWithMarkup'时出错)
全局代码(ReactComponentBrowserEnvironment.js:5:349)
[Error] ReferenceError: Can't find variable: process
全局代码(CSSPropertyOperations.js:17)
[错误] TypeError: 未定义不是一个对象(在评估'module$private/tmp$island$node_modules$react_dom$lib$DOMProperty["default"].ATTRIBUTE_NAME_START_CHAR'时出错)
全局代码(DOMPropertyOperations.js:9:200)
[错误] TypeError: 未定义不是一个对象(在评估'module$privateTMP$island$node_modules$react/lib$React["default"].isValidElement'时出错)
全局代码(LinkedValueUtils.js:9:533)
[Error] ReferenceError: Can't find variable: process
全局代码(ReactPropTypeLocationNames.js:2:193)
[Error] ReferenceError: Can't find variable: process
全局代码(ReactCompositeComponent.js:21:366)
[Error] ReferenceError: Can't find variable: process
全局代码(ReactMultiChild.js:21)
[Error] ReferenceError: Can't find variable: process
全局代码(ReactServerRenderingTransaction.js:10:126)
[Error] ReferenceError: Can't find variable: process
全局代码(validateDOMNesting.js:7)
[错误] TypeError: 未定义不是对象(在评估'module$private(tmp/island)node_modules/react_dom/lib/EventPluginHub["default"].deleteListener'时出错)
全局代码(ReactDOMComponent.js:42:171)
[错误] TypeError: 未定义不是对象(在评估'module$privatetmp$island$node_modules$react_dom/lib$DOMProperty["default"].injection'时出错)
全局代码(ReactInjection.js:13:279)
[Error] ReferenceError: Can't find variable: process
全局代码(ReactReconcileTransaction.js:18)
[Error] TypeError: undefined is not a function (near '...module$private$$tmp$$island$$node_modules$$react_dom$$lib$$SyntheticEvent["default"].augmentClass...')
全局代码(SyntheticAnimationEvent.js:4:256)
[Error] TypeError: undefined is not a function (near '...module$private$$tmp$$island$$node_modules$$react_dom$$lib$$SyntheticEvent["default"].augmentClass...')
全局代码(SyntheticClipboardEvent.js:4:303)
[错误] TypeError: 未定义不是一个函数(在'...module$private/tmp$island/node_modules/react_dom/lib/SyntheticUIEvent["default"].augmentClass...'附近)
全局代码(SyntheticFocusEvent.js:4:214)
[错误] TypeError: 未定义不是一个函数(在'...module$private/tmp$island/node_modules/react_dom/lib/SyntheticUIEvent["default"].augmentClass...'附近)
全局代码(SyntheticKeyboardEvent.js:10:95)
[错误] TypeError: 未定义不是一个函数(在'...module$privateTMP/island/node_modules/react_dom/lib/SyntheticMouseEvent["default"].augmentClass...'附近)
全局代码(SyntheticDragEvent.js:4:214)
[错误] TypeError: 未定义不是一个函数(在'...module$private/tmp$island/node_modules/react_dom/lib/SyntheticUIEvent["default"].augmentClass...'附近)
全局代码(SyntheticTouchEvent.js:6:95)
[Error] TypeError: undefined is not a function (near '...module$private$$tmp$$island$$node_modules$$react_dom$$lib$$SyntheticEvent["default"].augmentClass...')
全局代码(SyntheticTransitionEvent.js:4:257)
[错误] TypeError: 未定义不是一个函数(在'...module$privateTMP/island/node_modules/react_dom/lib/SyntheticMouseEvent["default"].augmentClass...'附近)
全局代码(SyntheticWheelEvent.js:5:98)
[错误] TypeError: 未定义不是一个对象(在评估'module$privateTMP/island/node_modules/react_dom/lib/ReactInjection["default"].EventEmitter'时出错)
注入(ReactDefaultInjection.js:22:383)
全局代码(ReactDOMServer.js:6:257)
[错误] TypeError: 未定义不是一个对象(在评估'module$privateTMP/island/node_modules/react_dom/server["default"].renderToString'时出错)
全局代码(core.js:6)