← Home

Cljs Tips

15 August, 2024

Collection of tips of cljs from various sources. Whenever i found useful information that i need to understand, i'll take time to update and put the knowledge here.

NodeJS package.json "exports" field

Thursday, 15 Aug 2024

The exports field allows defining the entry points of a package when imported by name loaded either via a node_modules lookup or a self-reference to its own name. It is supported in Node.js 12+ as an alternative to the main that can support defining subpath exports and conditional exports while encapsulating internal unexported modules.

All paths defined in the "exports" must be relative file URLs starting with ./.

Contoh ini isi dari field exports untuk npm package react.

  "exports": {
    ".": {
      "react-server": "./react.shared-subset.js",
      "default": "./index.js"
    },
    "./package.json": "./package.json",
    "./jsx-runtime": "./jsx-runtime.js",
    "./jsx-dev-runtime": "./jsx-dev-runtime.js"
  },

Directly import file not conform with the allowed list, e.g. /cjs/react.production.min.js is not permitted.

ShadowCljs versi > 2.20.16 follow this rule and will fail with error something like below:

package react had exports, but could not resolve ./cjs/react.production.min.js

To bring back old behavior, use :js-option {:ignore-exports true}.

Get use location from browser

Thursday, 15 Aug 2024

(-> js/navigator
    (.-geolocation)
    (.getCurrentPosition
      (fn [x] 
        (prn (cljs-bean.core/bean x))
        (js/console.log (.toJSON x)))))