1

我正在尝试将uber/react-map-gl与 Clojurescript 一起使用。我已将其添加到project.clj-

:npm-deps {"@cljs-oss/module-deps" "^1.1.1"
           :react-map-gl "^3.3.0-alpha.5"
           :react "^16.4.1"}

npm install单独编辑。当我从我的 ns 要求它时 -

(:require [react-map-gl :as M 
                        :refer [BaseControl TRANSITION_EVENTS 
                                FlyToInterpolator]])

(js/console.log M)
(js/console.log BaseControl)
(js/console.log M/BaseControl) ;;-> also fails

M已正确记录到控制台,但深入研究属性(例如BaseControl)会引发异常 -

Exception: ReferenceError: 
...$node_modules$react_map_gl$dist$esm$components$base_control is not defined at Object.get BaseControl [as BaseControl] (http://localhost:3449/js/compiled/out/node_modules/react-map-gl/dist/esm/index.js:5:19) at Object.remoteFunction (<anonymous>:2:14)]

少数属性是可访问的(例如,没有例外),例如TRANSITION_EVENTSFlyToInterpolator

我看到了这个错误(可能相关也可能不相关),但我不确定如何继续甚至排除故障。这是重现的最小失败示例。任何帮助,将不胜感激。

4

1 回答 1

1

这不是答案(实际上只是评论)。

通过首先手动要求所有组件和覆盖层(这表明某些部门管理不善),我表面上能够走得更远。

$ clj -m cljs.main -co compile-opts.edn -r
ClojureScript 1.10.339
cljs.user=> (require '"react-map-gl/dist/esm/components/popup"
 '"react-map-gl/dist/esm/components/navigation-control"
 '"react-map-gl/dist/esm/components/interactive-map"
 '"react-map-gl/dist/esm/components/base-control"
 '"react-map-gl/dist/esm/components/static-map"
 '"react-map-gl/dist/esm/components/marker"
 '"react-map-gl/dist/esm/overlays/svg-overlay"
 '"react-map-gl/dist/esm/overlays/html-overlay"
 '"react-map-gl/dist/esm/overlays/canvas-overlay"
 '[react-map-gl :as M
                        :refer [BaseControl TRANSITION_EVENTS
                                FlyToInterpolator]])

cljs.user=> M
#js {:default nil, :InteractiveMap nil, :StaticMap nil, :BaseControl nil, :Marker nil, :Popup nil, :NavigationControl nil, :CanvasOverlay nil, :HTMLOverlay nil, :SVGOverlay nil, :TRANSITION_EVENTS #js {:BREAK 1, :SNAP_TO_END 2, :IGNORE 3}, :TransitionInterpolator #object[TransitionInterpolator], :LinearInterpolator #object[LinearInterpolator], :FlyToInterpolator #object[ViewportFlyToInterpolator], :experimental #js {:MapControls #object[MapControls]}}

您可以看到,虽然这避免了...$node_modules$react_map_gl$dist$esm$components$base_control is not defined错误,但它并不是真正的解决方案,因为:BaseControl最终成为nil.

您可以通过对编译器进行修订以记录对cljs.closure/index-node-modules.

我的deps.edn

{:deps {org.clojure/clojurescript {:mvn/version "1.10.339"}}}

compile-opts.edn

{:npm-deps {:react-map-gl "^3.3.0-alpha.5"
            :react "^16.4.1"}
 :install-deps true
 :output-dir "out"}
于 2018-07-27T23:12:07.387 回答