Fork me on GitHub
#cljs-dev
<
2022-05-30
>
athomasoriginal20:05:58

RE: possible node module indexing bug in CLJS compiler > I think “node module indexing” is what it’s called 😬 If you use an NPM library which specifies a :main file with a .cjs ext in its package.json (see https://github.com/reactchartjs/react-chartjs-2/blob/master/package.json#L27) CLJS can’t find it during the https://github.com/clojure/clojurescript/blob/e30e26dbd221b5d7c4bbc567d10d0c3c01cf5f98/src/main/clojure/cljs/closure.clj#L2871 process. This issue seems to have also been mentioned on https://clojurians.slack.com/archives/C03S1L9DN/p1634583387258500. To verify this, I went into my project’s local node_modules package for react-chartjs-2 and updated the main from ./dist/index.cjs to ./dist/index.js . This resolved the issue. Once I confirmed the above, I then modified CLJS itself: https://github.com/clojure/clojurescript/blob/e30e26dbd221b5d7c4bbc567d10d0c3c01cf5f98/src/main/clojure/cljs/closure.clj#L2854 from

(into [(str entry-path ".js") (str entry-path "/index.js") (str entry-path ".json")])))))))
to
(into [(str entry-path ".js") (str entry-path "/index.js") (str entry-path ".json") (string/replace entry-path #"\.cjs$" ".js")])))))))
And the above change also resolves the issue (without needing to manually update your node_modules). It would be great if more experienced CLJS compiler devs could let me know if this is indeed an issue and would a minimal repro be useful?