NPM软件包无法在Clojurescript中编译

时间:2018-07-27 15:10:06

标签: clojurescript google-closure-compiler clojurescript-javascript-interop

我正在尝试将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

我看到了this bug(可能相关,也可能不相关),但是我不确定如何继续进行故障排除。这是minimal failing example可以复制的。任何帮助将不胜感激。

1 个答案:

答案 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"}