Fork me on GitHub
Yosevu Kilonzo02:03:13

Is there a better way to import and use an ESM only npm package like rehype-react than accessing the default property:

(ns uniorg-test.core
   ["unified" :refer [unified]]
   ["uniorg-parse" :as uniorg-parse]
   ["uniorg-rehype" :as uniorg-rehype]
   ["uniorg-extract-keywords" :as extract-keywords]
   ["rehype-react" :as rehype-react]
   ["react" :refer [createElement]]))

(def processor (-> (unified)
                   (.use uniorg-parse)
                   (.use extract-keywords)
                   (.use uniorg-rehype)
                   (.use (.-default rehype-react) #js {:createElement createElement})))

(.then (.process processor "* hello org-mode") #(.log js/console %))))

Yosevu Kilonzo13:03:37

Ah, thanks! I take a look at that.


so ["rehype-react$default" :as rehype-react]

wow 1

I bumped some JS dependencies, and I’m now seeing an error I haven’t seen before:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/me/project/node_modules/refractor/index.js from  /Users/me/project/app.js not supported.
Instead change the require of index.js in  /Users/me/project/app.js to a dynamic import() which is available in all CommonJS modules.
This was after bumping refractor from 3.3.1 to 4.2.2 . The app.js is built as target :node-library. Is this a known issue with a known fix? I see they converted the refractor code to ESM between those versions, so it now requires import x from y, but app.js contains require("x")


hmm yeah that is a node issue


shadow-cljs :node-library generates commonjs code and that is not allowed to require ESM code. so it fails with that error.