Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jack In does not complete when used with mixed Lein / Shadow-CLJS projects #314

Closed
aeberts opened this issue Sep 13, 2019 · 14 comments
Closed

Comments

@aeberts
Copy link

aeberts commented Sep 13, 2019

Config:

  • OS: MacOS High Sierra 10.13.6
  • Calva Version: v2.0.35-wip-custom-repl-connect-sequence
  • VSCode: Version: 1.38.0 Commit: 3db7e09f3b61f915d03bbfa58e258d6eee843f35
  • Clojure Project Template: https://github.com/Day8/re-frame-template

Summary:
Issuing the command Calva: Start a Project REPL and Connect (aka Jack In) does not complete when used with mixed Lein / Shadow-CLJS projects.

Reproduction Steps

  • Install Calva version v2.0.35-wip-custom-repl-connect-sequence in VSCode
  • Install re-frame template with lein new re-frame projectname
  • Open project folder in VSCode
  • Issue command Calva: Start a Project REPL and Connect

Expected Behaviour

  • Project compiles and a REPL window is displayed

Actual Behaviour

  • The project compiles but the REPL window is not displayed

Notes:
Note that the terminal window does appear pops up and code appears to be compiled correctly. The app is running and I'm able to visit the app url in the browser. Devtools in Chrome shows that shadow-cljs successfully created a websocket and a REPL connections but no REPL window is created.

The message at the bottom of VS Code: Launching a REPL using Leiningen and Disconnected

One other thing to note is that this template uses both leiningen and shadow-cljs. The project.clj is setup with lein aliases that call shadow-cljs like this:

:aliases {"dev"  ["with-profile" "dev" "run" "-m" "shadow.cljs.devtools.cli" "watch" "app"]
            "prod" ["with-profile" "prod" "run" "-m" "shadow.cljs.devtools.cli" "release" "app"]}

Workaround:
Workaround suggested by @PEZ on Slack #calva-dev
(https://clojurians.slack.com/archives/CBE668G4R/p1568316523297200)
I think it’ll be a bit of work to fix it properly. I’d appreciate if you could file an issue about this. Since it is a template that I presume is pretty popular, we’ll put it on high priority. That said, all is not lost. There is a quirky workaround to get the repl connected:

  1. Jack in and choose project type Leiningen
  2. Choose launch with alias dev
  3. Skip picking a profile.
  4. Wait for shadow to build the app. (Calva will not connect, because reasons).
  5. Issue the command Connec to a running REPL, and choose project type shadow-cljs
  6. Choose build :app

Quirky, as advertised. 😃 Here’s a way to unquirk it some. Put this in workspace settings.json:

"calva.replConnectSequences": [
       {
           "name": "Leiningen start REPL",
           "projectType": "Leiningen",
           "cljsType": "shadow-cljs",
           "menuSelections": {
               "leinAlias": "dev",
               "leinProfiles": []
           }
       },
       {
           "name": "shadow-cljs Connect",
           "projectType": "shadow-cljs",
           "cljsType": "shadow-cljs",
       }
   ]

Then:

  1. Jack in and choose Leiningen start REPL
  2. Wait for shadow to build the app. (Calva will not connect, because reasons).
  3. Connect to Running REPL and choose shadow-cljs Connect
@PEZ
Copy link
Collaborator

PEZ commented Sep 13, 2019

Hello there! Now there is a prerelease of Calva containing a fix for this issue. Can you put it to a test and see if you agree it is fixed? https://github.com/BetterThanTomorrow/calva/releases/tag/v2.0.37-wip-sequence-portfile

To test it. Download the VSIX file in that release. Then install it in VS Code via the Extensions pane meatballs menu: Install from VSIX....

@aeberts
Copy link
Author

aeberts commented Sep 13, 2019

Hi! Wow - quick turn-around 😄

Yes, the bug appears to be fixed at a high-level.

Evaluation steps:

  • Download and install new v2.0.37-wip-sequence-portfile
  • Verify new version installed correctly with Extensions -> Calva "gear" icon -> "Copy Extension Information"
  • Open lein + shadow-cljs project in VSCode
  • Issue command Calva: Start a Project REPL and Connect and choose Leiningen + shadow-cljs
  • Verify that lein task is running in VSC Terminal -> code compiles (*see additional notes below for terminal output)
  • Open browser and visit development server url -> application loads sucessfully.
  • Open browser dev tools to check shadow-cljs status -> WebSocket connected and Repl started.
  • Return to VSC and verify that Calva REPL window opens -> success
  • Open CLJS project file utils.cljs and issue Load current namespace in REPL Window -> success - REPL window shows current namespace.
  • Evaluate Send current form to REPL -> command is executed but output only appears in browser's dev tools window. REPL window output: nil (I expected to see output in the Calva REPL window as well as browser dev tools but maybe I'm missing something?).

Code evaluated:

(defn prn-db []
  "Utility function to print database to the console"
  (pp/pprint (d/datoms (deref db/conn) :eavt)))

(comment 
  (prn-db) ;; <- send current form to REPL evaluated here
)

Additional Notes:

Terminal output of compilation stage - note message re: cider-nrepl.

> Executing task: lein update-in :dependencies conj '[nrepl"0.6.0"]' -- update-in :dependencies conj '[cider/piggieback"0.4.1"]' -- update-in :dependencies conj '[cider/cider-nrepl"0.22.1"]' -- update-in :plugins conj '[cider/cider-nrepl"0.22.1"]' -- update-in '[:repl-options :nrepl-middleware]' conj '["cider.nrepl/cider-middleware"]' -- update-in '[:repl-options :nrepl-middleware]' conj '["cider.piggieback/wrap-cljs-repl"]' -- dev <

Warning: cider-nrepl requires Leiningen 2.8.3 or greater.
Warning: cider-nrepl will not be included in your project.
Warning: cider-nrepl requires Leiningen 2.8.3 or greater.
Warning: cider-nrepl will not be included in your project.
Warning: cider-nrepl requires Leiningen 2.8.3 or greater.
Warning: cider-nrepl will not be included in your project.
Warning: cider-nrepl requires Leiningen 2.8.3 or greater.
Warning: cider-nrepl will not be included in your project.
shadow-cljs - HTTP server available at http://localhost:8280
shadow-cljs - server version: 2.8.52 running at http://localhost:9630
shadow-cljs - nREPL server started on port 8777
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
[:app] Build completed. (595 files, 1 compiled, 0 warnings, 7.30s)

My local Leiningen configuration:

-> lein --version
Leiningen 2.9.1 on Java 1.8.0_212 OpenJDK 64-Bit Server VM

Hope that helps! Please let me know if you want more info.

@PEZ
Copy link
Collaborator

PEZ commented Sep 14, 2019

Thanks for the test report!

The lack of output from stdout is an issue Calva has with shadow-cljs.

The warnings confuse me. I don't get those. The output looks like so on my machine:

> Executing task: lein update-in :dependencies conj '[nrepl"0.6.0"]' -- update-in :dependencies conj '[cider/piggieback"0.4.1"]' -- update-in :dependencies conj '[cider/cider-nrepl"0.22.1"]' -- update-in :plugins conj '[cider/cider-nrepl"0.22.1"]' -- update-in '[:repl-options :nrepl-middleware]' conj '["cider.nrepl/cider-middleware"]' -- update-in '[:repl-options :nrepl-middleware]' conj '["cider.piggieback/wrap-cljs-repl"]' -- with-profile +dev dev <

Leiningen's classpath: /Users/pez/.lein/self-installs/leiningen-2.9.1-standalone.jar
Applying task update-in to [:dependencies conj [nrepl"0.6.0"] -- update-in :dependencies conj [cider/piggieback"0.4.1"] -- update-in :dependencies conj [cider/cider-nrepl"0.22.1"] -- update-in :plugins conj [cider/cider-nrepl"0.22.1"] -- update-in [:repl-options :nrepl-middleware] conj ["cider.nrepl/cider-middleware"] -- update-in [:repl-options :nrepl-middleware] conj ["cider.piggieback/wrap-cljs-repl"] -- with-profile +dev dev]
Applying task update-in to [:dependencies conj [cider/piggieback"0.4.1"] -- update-in :dependencies conj [cider/cider-nrepl"0.22.1"] -- update-in :plugins conj [cider/cider-nrepl"0.22.1"] -- update-in [:repl-options :nrepl-middleware] conj ["cider.nrepl/cider-middleware"] -- update-in [:repl-options :nrepl-middleware] conj ["cider.piggieback/wrap-cljs-repl"] -- with-profile +dev dev]
Applying task update-in to [:dependencies conj [cider/cider-nrepl"0.22.1"] -- update-in :plugins conj [cider/cider-nrepl"0.22.1"] -- update-in [:repl-options :nrepl-middleware] conj ["cider.nrepl/cider-middleware"] -- update-in [:repl-options :nrepl-middleware] conj ["cider.piggieback/wrap-cljs-repl"] -- with-profile +dev dev]
Applying task update-in to [:plugins conj [cider/cider-nrepl"0.22.1"] -- update-in [:repl-options :nrepl-middleware] conj ["cider.nrepl/cider-middleware"] -- update-in [:repl-options :nrepl-middleware] conj ["cider.piggieback/wrap-cljs-repl"] -- with-profile +dev dev]
Applying task update-in to [[:repl-options :nrepl-middleware] conj ["cider.nrepl/cider-middleware"] -- update-in [:repl-options :nrepl-middleware] conj ["cider.piggieback/wrap-cljs-repl"] -- with-profile +dev dev]
Applying task update-in to [[:repl-options :nrepl-middleware] conj ["cider.piggieback/wrap-cljs-repl"] -- with-profile +dev dev]
Applying task with-profile to [+dev dev]
Applying task [with-profile dev run -m shadow.cljs.devtools.cli watch app] to nil
Applying task run to (-m shadow.cljs.devtools.cli watch app)
Applying task javac to nil
Running javac with [@/var/folders/2n/phzlvbn557g13p0pp7wzt3jr0000gn/T/.leiningen-cmdline257494973614059523.tmp]
Applying task compile to nil
All namespaces already AOT compiled.
shadow-cljs - HTTP server available at http://localhost:8280
shadow-cljs - server version: 2.8.52 running at http://localhost:9630
shadow-cljs - nREPL server started on port 8777
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
[:app] Build completed. (203 files, 1 compiled, 0 warnings, 2,93s)

I'm also using Leiningen 2.9.1 (as can be seen in the output even). I am using Java 12, however. Maybe that makes some difference...

@PEZ PEZ closed this as completed in d8c0d5a Sep 14, 2019
@gmp26
Copy link

gmp26 commented Mar 19, 2020

I continue to hit this issue with current Calva (i.e. not completing cljs jack in) with the lein re-frame template. After making settings.json edits above and following @aeberts evaluation steps I hit this classpath error:

Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:381).
shadow.cljs.devtools.api
Error while connecting cljs REPL: TypeError: Cannot read property 'search' of undefined

My workaround is to start the app in a terminal with lein dev, load it in the browser, and then use
Connect to a running repl - (alt-ctl-C alt-ctl-C) - shadow-cljs Connect to localhost:8777. Then select the :app build.

Bit much for my little brain to remember! :)

Same results with JDK8 and 12.

@PEZ
Copy link
Collaborator

PEZ commented Mar 19, 2020

@gmp26 What if you remove the settings.json changes and:

  1. Jack-in
  2. Select shadow-cljsproject type.
  3. Select to start build :app

Does it still not work?

@gmp26
Copy link

gmp26 commented Mar 19, 2020

@PEZ Brilliant :) Thank you so much! I suspect my settings.json were initially a hangover from a previous project and so I started following this issue to fix the problem. So now I just have

"calva.replConnectSequences": [
 ],

which works fine. Maybe I could even delete that?

@PEZ
Copy link
Collaborator

PEZ commented Mar 19, 2020

Awesome! Yes, you are probably better off without that as well.

@gmp26
Copy link

gmp26 commented Mar 19, 2020

It's gone, and we still have jack-in!

@loganpowell
Copy link

I'm having a similar issue:

Connecting cljs repl: shadow-cljs...
The Calva Connection Log might have more connection progress information.
Error while connecting cljs REPL: TypeError: Cannot read property 'search' of undefined

@muhajirdev
Copy link

I am having a similar issue too

@PEZ
Copy link
Collaborator

PEZ commented Apr 16, 2021

Oh, I've missed your comment, @loganpowell . Sorry about that. Are you still having the problem?

@muhajirdev , ”similar” can mean many things. 😄 Can you elaborate some? What are the steps you take, what happens/does not happen? Such things.

@muhajirdev
Copy link

Hi @PEZ sorry for not providing extra details

I recorded this video,

https://www.loom.com/share/ec1afd444d394fac90097fca5de18ced

as additional information I am using calva 2.0.187
image

Also, when I tried with luminusweb.com, it can connect repl. I don't know if this problem is specific to reframe-template

Thanks for your help @PEZ :)

@PEZ
Copy link
Collaborator

PEZ commented Apr 16, 2021

Thanks for the repro video. That does look like something is broken. Can you file it as a new issue?

@PEZ
Copy link
Collaborator

PEZ commented Apr 16, 2021

I got it working, btw. But let's continue in a separate issue, because this is different than the OP.

PEZ added a commit to PEZ/re-frame-template that referenced this issue Apr 16, 2021
superstructor pushed a commit to day8/re-frame-template that referenced this issue Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants