Anyone Have Luck With "JS Modules (Alpha)" ClojureScript Guide?

I came across the JS Modules (Alpha) and gave following the implementation a go.

After an hour of getting Error: Cannot find module '@cljs-oss/module-deps' or the script not running due to the module not being provided (no matter what I do), I don’t want to sink any more time into before see if others have had luck following the guide.

If you have any suggestions or a repo to share with a working example, it would be much appreciated.

cljs version I am using by the way is: 1.11.54

2 Likes

What specifically are you trying to do? Most of the stuff described there is obsolete by todays standards.

Good question! As an exercise in learning the base cljs toolset, rather than pulling in other build tools.

You must like pain. Most people use shadow-cljs or figwheel, at least for development.

I’d say all of the described stuff in that post should be considered dead and unsupported. And more importantly you most likely don’t need any of it anyways. Say you want to write some JS code and use it from CLJS.

Assuming your source path includes src/main and your CLJS namespace is demo.app. So you’d have a src/main/demo/app.cljs. You can create a src/main/demo/foo.js file.

In that file write

goog.module("demo.foo");

exports.foo = function(x) { return x + 1; };

From CLJS you can do

(ns demo.app
  (:require [demo.foo :as x]))

(js/console.log "calling foo" (x/foo 1))

Thats it. Doesn’t require any configuration. shadow-cljs has extended support for using ESM/CommonJS code directly, but goog.module should work everywhere without extra config.

As for the transform stuff I’d keep that out of the CLJS tooling completely.

1 Like

Nailed it! :laughing:

Thanks, I’ll give it a shot!

I concur, have used shadow-cljs personally and professionally. As an aside, appreciate the work and time you’ve put into shadow-cljs and for taking the time to respond to my query!