0

I have started using the :target :nodejs compiler options for a cljs project (src). By and large, it works well.

However, when attempting to convert @mapbox/react-native-mapbox-gl to the updated require syntax, e.g.

(:require [@mapbox/react-native-mapbox-gl])

it fails -

Library name must be specified as a symbol

as the npm module is scoped with @. Using a string does not work either.

This works-

(set! js/MapboxGL (js/require "@mapbox/react-native-mapbox-gl"))

But I was curious if there was any way to get this compiled with the require syntax.

nrako
  • 2,952
  • 17
  • 30

1 Answers1

1

if you using 1.9.854 or above,

you can now use string in :require

(:require ["@mapbox/react-native-mapbox-gl" :as mapbox])

hope you enjoy using ClojureScript

ka yu Lai
  • 571
  • 3
  • 13
  • Thanks for the note. I will give this a shot when I return to the project next week and report back. – nrako Dec 17 '17 at 06:57
  • 1
    It turns out that the Mapbox lib returns an object that must be accessed from `:default`, e.g. `(def _map (.-default mapbox))`, which is why it failed when I tried a string originally. Thanks for the note. Your answer works great. – nrako Dec 19 '17 at 19:40
  • really recommend everyone to join clojure's slack channels. you can get more fast and good answer – ka yu Lai Dec 20 '17 at 09:20