Some npm packages fail to require

Description

To reproduce:

This results in this error:

Environment

None

Activity

Show:
Dieter Komendera
January 13, 2021, 9:43 AM

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.

Juho Teperi
January 14, 2021, 4:03 PM
Edited
Dieter Komendera
January 17, 2021, 10:20 AM

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*:

https://github.com/clojure/clojurescript/blob/496cbc294d8503be38253dc6a5042fca721892a8/src/main/clojure/cljs/closure.clj#L2742

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.

Dieter Komendera
January 22, 2021, 3:06 PM

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

https://github.com/clojure/clojurescript/blob/496cbc294d8503be38253dc6a5042fca721892a8/src/main/clojure/cljs/closure.clj#L2509-L2515

Assignee

David Nolen

Reporter

Dieter Komendera

Labels

None

Approval

None

Patch

None

Priority

Major