react-nativeclojurescriptre-natal

Require scoped module in Clojurescript


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.


Solution

  • 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