Fork me on GitHub

hi! i am trying in vain to use a npm module with a new cljs project. this is my first time using the cljs ecosystem, and am working to port my library to the runtime. could someone help me with some basics?

dsp12:04:37 here's the skeleton project as it stands currently

dsp12:04:19 - i added lein-npm, and added :npm {:dependencies [[bytebuffer "5.0.1"]]}


this is the package that i'd like to be using:


(my clojure lib uses java bytebuffers heavily, so was looking for a nice compat layer)


the issue i see is, when doing lein fig:build:

[Figwheel] Validating figwheel-main.edn
[Figwheel] figwheel-main.edn is valid \(ツ)/
[Figwheel] Compiling build dev to "resources/public/cljs-out/dev-main.js"
    throw err;

Error: Cannot find module '@cljs-oss/module-deps'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at [eval]:8:13
    at Script.runInThisContext (vm.js:122:20)
    at Object.runInThisContext (vm.js:329:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at evalScript (internal/bootstrap/node.js:590:27)


i must be missing something, or doing something horribly wrong.


just for completion: works fine for node.

> var ByteBuffer = require("bytebuffer");
> var bb = new ByteBuffer();
> bb
ByteBuffer {
  buffer: <Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>,
  offset: 0,
  markedOffset: -1,
  limit: 16,
  littleEndian: false,
  noAssert: false }


Just my 5c - if you plan to use NPM modules often, you may find shadow-cljs much better than other tools.


thankfully I just discovered cljsjs, and it seems packaged. means i don't learn what i did wrong, but i can now access the functions as expected, so the outcome is fine.


cljsjs is a ticking bomb though in terms of maintenance of your own project. A moment will come when you stumble upon a poorly maintained library or just a non-existing one.


It may very well be that you did nothing wrong. Maybe it's just that Figwheel and the default CLJS compiler don't support that particular module for whatever reason.


fair enough. the cljs ecosystem has even less documentation than clojure does, which is expected for something with fewer users i suppose. i guess it's also a fast-moving target? at least for my use case, i just want to implement a compatibility shim around JVM ByteBuffers so that I can use the same implementation for working on them in clj and cljs, without rewriting too much. originally was going to implement the stuff myself, but then found a npm module that did 90% already.


What documentation do you find missing?


It's not that fast moving, no. Much more stable than regular JS. :)


mostly best-practice beginner stuff. this is day 0 for me getting started with cljs. there does not appear to be any obvious way for me to start a skeleton project (i experimented with several before getting to a repl, and still was unsure whether i was doing the correct thing.) i admit i am not a clojure expert, and some of the java interop stuff is still a little over my head, but it took me some time to realise that i should probably not be doing stuff here and stumbling across cljsjs, which you suggest i also probably avoid. took me some time to realise that cljsjs imports do not follow the regular require :as syntax (or i did it incorrectly)


In what languages do you have experience?


lots of non-obvious stumbling blocks that i only chip away at when reading blog posts or thorugh experimentation. maybe i'm missing something, but it's an adventure to bootstrap at least. not really criticism, just hard nonobvious work. i'm using a lot of stuff that when getting started is not really explained. is a perfect example - would be an improvement if there were snippets about why one would choose any of those options. today much is "left as an exercise for the reader".


c, scheme, perl, common lisp, java, erlang


0 previous js experience


i suppose a lot of people trying clojurescript for the first time come from a javascript background? i dunno. but for me, this is my first excursion into that ecosystem, coming instead from the jvm, just as a way to make my lib available to both runtimes


so my learning path will be, get cljs bootstrapped, import required javascript stuff, then make a clj+cljs project, experiment with reader conditionals, then hopefully take all that knowledge and apply it to my actual project and hope for the best


Regarding those templates - IMO it wouldn't make sense to add a deeper overview of the options simply because the links can be followed where a guaranteed up-to-date descriptions could be found. If you copy the descriptions over, they will inevitably get stale an confuse people. Regarding what to choose - it doesn't really matter. Templates just help developers to skip some steps. The thing about novices is that there are no steps that can be skipped - a novice either don't need those steps at all or has to go through them manually to understand what's going on. With that being said, you probably should start with no template at all. Or maybe the simplest template you can find. Or maybe, if you prefer adapting some already working code to your needs, just find one of many CLJS App showcases out there. "TODO App" is a good one, especially if you want to tackle UI. Regarding best practices - a common way of doing things in many languages is using all encompassing frameworks and adopting some paradigm. A common way of doing things in CLJ(S) world is to pick your own libraries to mix and match to the desired extent. Of course, there are big libraries, paradigms, and even frameworks out there, but far less invasive than in other ecosystems. And that's roughly why it's hard to find best practices - because people just find what's best for them. A sane default to get you started is probably to stick to the most popular libraries within any particular niche. Even if you commit to some set of libraries, it's usually not that hard to switch to a different one. Regarding getting started in general - a very trivial advice, but I cannot stress this enough: read the documentation. Do not skip right to the examples. You may skip stuff that you won't need at all (React Native, for example), but don't skip the main stuff. Choose a build tool, find its documentation, and read through it while trying things out. Yet again, my recommendation is shadow-cljs, in this case because its documentation is stellar. If you do that, you will be better off than 90% of beginners.


well, i have read the documentation, my point is that much is not documented in a way that is either authoritative or discoverable. i am not a novice, have experience professionally with clojure, and am explicitly only looking at cljs to port a clj-only open lib i wrote to support both runtimes. i'll take notes on the learning process and publish something highlighting possible areas for improvement once the work is complete. i solved the issue myself regardless, so this thread serves little further purpose (though the original issue that i asked for help with persists, i found a workaround). i'll check out shadow-cljs at a later point, since i'm now already at the stage where i can continue writing actual project-relevant code. thanks for the input .

Oliver George12:04:35

I'm playing around with the new I'd like my reagent component to be displayed in a React Storybook. Things are mostly working but I can't workout how to generate the export default ... to expose my component to the story.


@dnolen I’ve started using Krell and it’s quite brilliant. everything seems to work. one thing I wonder about is your development style and connecting to REPL. do you connect with Krell REPL from Emacs/Cider of some other IDE/editor? or just keep it running in terminal?


@andrzej.fricze there's some bugs around Android which I'm fixing today so I wouldn't go crazy w/ it quite yet - the REPL is just a standard Clojure-style REPL

👍 8

it can work anywhere as long as the tooling supports that style of REPL


there's no plans to build any kind of nREPL support - that's up to somebody else to figure out and not in Krell itself - though I'm not against providing hooks if it's reasonable

👍 4

to me tools that don't support plain REPLs and only nREPL are a huge problem

👍 12

I see, thanks for explanation :thumbsup:


What's an idiomatic way to access a global JS variable that may not be defined? For example, determining if "window" is available. If you just use js/window you'll get a ReferenceError on node.js Right now I'm using:

(= (js* "typeof window") "undefined")
I was also considering wrapping the js/window form in a try/catch, but went with the above approach instead. I'm curious if there are other solutions.


I think this is what exists? is for


Big refactor and extension of inf-clojure happening. will make working with the non-nrepl tooling much nicer from emacs. if you couple with clojure-lsp you largely get a cursive-like

👀 8

inf-clojure already works with a socket repl for me, is this something different?


making sure it doesn't throw weird errors on completions for planck, the startup was weird. and the code base was pretty scrambled. you can follow here:


nice, yeah its needs some love


I recently switched to cider because pretty printing to a popup buffer is such a convenient feature.


I had a workaround in inf-clojure but it wasn't as nice


that's a good idea. should be implementable in inf-clojure


@dpassen1 thanks! that works

👍 4

Heya, I've made a new tool for React Native - my company Vouch supported this open source development effort - we used re-natal for a couple of years and while useful - in the end it stuck out in our workflow - not very Clojure-y


it uses the :bundle target from ClojureScript master - the goal here was to be ultra-minimal - if you're familiar with the ClojureScript Quick Start, you can make a React Native app


we don't try to paper over the React Native CLI at all - it just the stuff that Clojure(Script) programmer should care about - a REPL, and a hot loader

✔️ 20

it makes no assumptions about what ClojureScript library you may want to use - but I made a beginning to end tutorial for Reagent

👍 28

should be trivially adaptable to any other ClojureScript React binding


we're still collecting feedback and bug reports - so no artifact yet - after a couple of weeks of kicking the tires we'll push something to Clojars and you won't have to use the git dep


Out of curiosity: is there a story behind the name? (since I'll be reading that often, calling krell.main...)


also if you're into modular synthesis, Todd Barton has a famous generative patch called the "Krell Patch", this comes from how the original soundtrack was created -

👌 20

is there a way to have shadow-cljs release app produce a source map, for production builds?