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).
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:
Default should already prefer module over main, except on :target :nodejs.
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