funcool / decimal

An arbitrary-precision Decimal type for ClojureScript
http://funcool.github.io/decimal/latest/
BSD 2-Clause "Simplified" License
13 stars 6 forks source link

Compilation fails under shadow-cljs #7

Open achikin opened 5 years ago

achikin commented 5 years ago

Compilation fails while trying to compile the library with shadow-cljs. The following error is shown.

The required namespace "decimal.extern.decimaljs" is not available, it was required by "decimal/core.cljs".
achikin commented 5 years ago

shadow-cljs does not support foreign libs inside cljs libraries. As per Thomas Heller advice - you should fetch decimal.js from npm separately and create the following namespace to make the npm version available to funcool/decimal

;;file: src/cljs/decimal/extern/decimaljs.cljs adjust according to your code layout
(ns decimal.extern.decimaljs
  (:require ["decimal.js" :as decimal-js]))
(js/goog.exportSymbol "Decimal.noConflict" (fn [] decimal-js))
jjttjj commented 3 years ago

While @achikin's solution works, would it be a good idea to support compilation with shadow out of the box? Shadow is somewhat popular these days and it might be a best practice for a small useful library like this to work with at least the most common cljs build tools without having to add an additional namespace.

There is a good writeup on packaging cljs libs here: https://widdindustries.com/cljs-npm-libraries/