Fork me on GitHub
#cider
<
2023-03-25
>
hifumi12300:03:06

Are you on Mac or Linux? I would probably just change cider-shadow-cljs-command

hifumi12300:03:02

where do global npm packages get installed on linux? basically, we can either fix the PATH or we can just (setq cider-shadow-cljs-command "/full/path/to/shadow-cljs")

frozenlock00:03:03

I have a .npm directory, but it looks like _npx is just weirdly named directories...

hifumi12300:03:24

actually what is the result of (executable-find "shadow-cljs")

hifumi12300:03:55

ok yeah just find whatever the full path is on your system and set it explicitly

hifumi12300:03:02

im not very familiar with linux paths

frozenlock00:03:20

The path to shadow-cljs? Will it be a binary?

hifumi12300:03:17

On my machine it seems to be a script

% file $(which shadow-cljs)
/opt/local/bin/shadow-cljs: a /usr/bin/env node script text executable, ASCII text

frozenlock00:03:47

ok I think I got it

hifumi12300:03:20

cool; now just make sure executable-find returns a non-nil value with the path, and if it does, try using it as your cider-shadow-cljs-command

frozenlock00:03:03

> error in process sentinel: Could not start nREPL server: /usr/bin/env: ‘node’: No such file or directory

frozenlock00:03:50

I'll try a fighweel-main project after all

hifumi12300:03:01

out of curiosity, do you have the exec-path-from-shell package installed? if not, then that may help you with PATH issues with Emacs

hifumi12300:03:08

otherwise I have no idea why emacs cant find anything on your system

frozenlock01:03:34

Ah great library. I added it to my config file, thanks!

frozenlock01:03:36

I was able to run shadow-cljs via CIDER with a lein reagent template. It works well, so I guess lein-figwheel is indeed a potential source for my issue 😞

frozenlock22:03:11

I just spent the day migrating to shadow-cljs, realizing it's way too reliant on npm , then migrating to figwheel-main ... and I have the same issue!

spam 2
thheller23:03:19

the only npm reliance shadow-cljs has the is the npm packages you use 😉

frozenlock23:03:54

Wouldn't I need to manually install most/all of my cljsjs dependencies? > The shadow-cljsjs library only provides the shim files. You’ll still need to npm install the actual packages yourself.

thheller23:03:29

most libraries nowadays have been updated to properly declare :npm-deps, so they'll be installed automatically. although you still want to keep track of them

frozenlock23:03:11

:thinking_face:

frozenlock23:03:26

So if react wasn't working, it was probably only because I didn't have shadow-cljsjs?

thheller23:03:08

npm install react is too much? 😛

thheller23:03:20

you always have shadow-cljsjs, it comes with shadow-cljs

thheller23:03:49

reagent and others all declare their react dependency properly

thheller23:03:56

don't know what you are using, so can't answer

frozenlock23:03:04

For a one-time, of course not. But in the grand scheme of things, it's adding one more build tool. In 4 years when I'll come back to the project, I will curse my past self 😕

thheller23:03:08

npm creates a package-lock.json, which ensures you get exactly the same dependencies in 4 years

thheller23:03:30

keep that + package.json in git and things should be fine

thheller23:03:56

not keeping the lock file is the sin that will break everything next week 😉

thheller23:03:38

but I understand the sentiment, not a fan of npm either myself.

frozenlock23:03:11

Sure, but I mean having to call npm install I know it's small, but I'd rather avoid having it if possible. Adding more dev tools is always painful in the long run.

hifumi12323:03:33

imo it’s much better than dealing with the (often errorneous) externs that ship with CLJSJS packages then debugging issues that only manifest in release builds

frozenlock23:03:34

But at least I have the shadow-cljs migration in a branch, so I can try to see if I had something else breaking things

hifumi12323:03:18

i used to find shadow-cljs super complicated when I was coming to cljs from clojure, but once it clicked, i never want to go back to other build tools… having to npm ci on my machine or in a CI build is not a big deal at all IMO… if anything, I’d say leiningen is the extra build tool that can go away (for a cljs frontend at least) 😄

hifumi12323:03:13

anecdotally, cljs projects have the most friction or ceremony to get running when people decide to mix them in with lein or deps.edn instead of just using shadow-cljs from npm directly

✔️ 2
frozenlock23:03:04

I'll try tomorrow morning then I can't be far from getting it to compile 😅

hifumi12323:03:12

if your project has managed to survive without needing to pull in any npm library that is not react, then I’d say there is a very good chance you should be migrating over to shadow-cljs

hifumi12323:03:10

i know this is another anecdote, but ive seen a cljs codebase old enough to migrate from Om to Reagent then Prismatic Schema to clojure.spec then lein-cljsbuild to figwheel and so on…. and migrating it over to shadow-cljs wasn’t a big hassle, it actually simplified the steps needed to set up a development environment on the app’s frontend

hifumi12323:03:32

of course not all cljs libraries out there are perfect… devcards has hard dependencies on cljsjs packages but you can shim them out and use the npm versions directly, but the only CLJS library that has given me issues with shadow-cljs has been, well, devcards. Everything else didn’t need me to put much effort or thought to add to my project.

frozenlock23:03:34

Very interesting; my project is roughly the same age then

frozenlock23:03:45

I do have a 'few' cljsjs deps

[cljsjs/codemirror "5.44.0-1"]
                 [cljsjs/filesaverjs "1.3.3-0"]
                 [cljsjs/moment "2.24.0-0"]
                 [cljsjs/react-beautiful-dnd "10.0.4-0"]
                 [cljsjs/react-grid-layout "0.17.1-0"]
                 [cljsjs/react-transition-group "1.2.0-0"]
                 [cljsjs/react-virtualized "9.21.2-1"]
                 [cljsjs/resize-observer-polyfill "1.4.2-0"]

hifumi12323:03:54

all of those should be simple to install from npm, the only change needed to your codebase is that (require '[cljsjs.moment :as moment]) becomes simply (require '["moment" :as moment])

hifumi12323:03:11

the good news is that you can just make shim namespaces so that you can “require” cljsjs.moment but under the hood its the npm version — this will greatly assist in migrating your codebase over

hifumi12323:03:54

of course, I understand your original issue is mostly CIDER REPL suddenly changing namespace to cljs.user every time a form is submitted in a separate namespace

hifumi12323:03:30

and while migrating to shadow-cljs is a non-trivial task — i think the benefits outweigh the costs here, assuming that CIDER plays nicely with shadow-cljs on your end (i.e. you can eval things without this namespace issue)

frozenlock23:03:32

Yeah it's far from my initial issue, but hey, if it can solve it AND prevent some painful migration later on 🤷

frozenlock23:03:28

By shimming namespaces, do you mean I should do (ns cljsjs.moment ...) , or is that something shadow-cljsjs does automatically?

hifumi12323:03:40

I believe there is a shadow-cljsjs library that can automagically generate shims for you, but I’ve never used it. The shims are very simple to set up anyway

thheller23:03:58

I don't recommend creating cljsjs namespaces. they only exist to help with libraries that use them

thheller23:03:12

for your own code it is best to start using the npm package directly

hifumi12323:03:18

the use case here is to prevent having to refactor an entire project beforehand, basically try getting the npm package to work with the codebase, then refactor so that the shims can be safely deleted

hifumi12323:03:53

but i guess rewrite-clj and related tools should help automate the process of changing the require s across files

thheller23:03:04

sure that is an option

frozenlock23:03:10

Alright, I try again in the morning. Thanks to you both 🙏

frozenlock22:03:23

It keeps returning to cljs.user

my.ns> (+ 1 1)
2
cljs.user>

hifumi12323:03:30

possible figwheel issue then. what youve describe basically never happens to me with shadow-cljs

hifumi12323:03:53

the only npm thing shadow-cljs needs is a websocket library; if invoking from lein then you will need an nrepl middleware for cider, but otherwise I dont see much reliance on npm

David Ackerman23:03:55

is it possible to run a function that returns a promise from the cider repl and have it inspect the value inside the promise instead of the promise itself? I know i can manually def the result from within a then and then evaluate that separately, but i'm trying to get my regular data-exploration workflow to work with promises. (i'm using nbb in case that matters)