ClojureScript :js-provider :external with :target :esm — Undefined Peer Dependency Resolution Boundary
0 reputation · 17 Aug 2021, 00:04 UTC
0 reputation · 17 Aug 2021, 00:04 UTC
When targeting native ES modules with :js-provider :external, the ClojureScript compiler generates import statements for each top-level entry in :npm-deps but performs no analysis of the npm dependency graph beyond those keys. Transitive dependencies and peer dependencies declared by those packages are omitted from the generated import map, leaving resolution entirely to a downstream bundler.
The documentation does not specify whether dependencies, peerDependencies, or optionalDependencies from the resolved npm packages should be treated as required imports. A library that re-exports submodules (for example, react-redux re-exporting react internals) will produce import specifiers only for the declared :npm-deps key, not for the peer react dependency that must be present at runtime.
If an :npm-deps entry points to a package that lacks a valid ES module entry point (no exports field, no module field, only CommonJS), the compiler emits an import statement that will fail at bundle time without any compile-time warning.
What is the documented contract between the ClojureScript compiler and the external bundler regarding peer dependency resolution? Should the compiler analyze peerDependencies of declared :npm-deps and emit additional import specifiers, or is that explicitly out of scope? Is there a supported mechanism to declare required peer dependencies so the generated import map is complete?
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.