我正在尝试将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_EVENTS
和FlyToInterpolator
。
我看到了this bug(可能相关,也可能不相关),但是我不确定如何继续进行故障排除。这是minimal failing example可以复制的。任何帮助将不胜感激。
答案 0 :(得分: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"}