To reproduce:
This results in this error:
Investigating this shows that the major difference between the failing @codemirror/state and other working npm packages is @codemirror/state having a main key in its packages.json ending in .cjs (instead of .js which most packages use).
See https://github.com/codemirror/state/blob/7445c01fa7a7545036a7b849b382b09a39cea5b0/package.json#L19
This prevents it from being successfully indexed by cljs.closure/index-node-modules-dir, as it tries to find the file from main in a file-seq from cljs.util/module-file-seq only containing .json and .js files.
The package also has module definition pointing to ES6 module:
https://github.com/codemirror/state/blob/7445c01fa7a7545036a7b849b382b09a39cea5b0/package.json#L25
https://unpkg.com/browse/@codemirror/state@0.17.1/dist/index.js
Default should already prefer module over main, except on :target :nodejs.
https://clojurescript.org/reference/compiler-options#package-json-resolution
Thanks for the pointer to :package-json-resolution . cljs.closure/index-node-modules-dir doesn’t respect that option though, only cljs.closure/index-node-modules does. index-node-modules-dir has the main key hardcoded via node-file-seq->libs-spec*:
CLJS-3293.patch makes index-node-modules-dir use :package-json-resolution (and its defaults) to pick the best fitting entry point from a package.json. A test is included as well.
CLJS-3293.patch doesn’t work when using :target :bundle, as this overrides the :target to :nodejs leading to again indexing the wrong entry key from the package.json