We're updating the issue view to help you get more done. 

Support ns :require for JS libs, allow strings along with symbols

Description

Requiring JS code from CLJS requires a lot of manual JS interop and can be simplified by allowing Strings in the ns form.

Instead of using (js/require "react") or relying on a provided global js/React it should be possible to write

1 2 3 (ns demo.foo (:require ["react" :as react :refer (createElement)]) (:import ["react-native" Text View]))

It is somewhat at odds with the current :foreign-libs and CLJSJS ecosystem since the intent is to directly consume NPM packages instead of relying on re-packaged NPM packages. node.js is able to directly use these requires but other runtimes (eg. browsers) require an additional build step that provides the NPM packages. :foreign-libs could probably be enhanced to provide "react" instead of cljsjs.react and then js/React.

I don't know what it would take to bring this into CLJS but I think it would be a useful feature. I have a working implementation in the shadow-cljs project [1] but unfortunately that is not easily portable due to significant differences in the compilation process. It currently only works for requiring packages (ie. "react") but not for relative requires (ie. "./foo") but :foreign-libs has the same limitation.

[1] https://github.com/thheller/shadow-cljs

Environment

None

Status

Assignee

David Nolen

Reporter

Thomas Heller

Labels

None

Approval

Accepted

Patch

Code and Test

Fix versions

Affects versions

1.9.562

Priority

Major