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

How To Use REPL? #33

Open
JimLynchCodes opened this issue Nov 24, 2017 · 7 comments
Open

How To Use REPL? #33

JimLynchCodes opened this issue Nov 24, 2017 · 7 comments

Comments

@JimLynchCodes
Copy link

JimLynchCodes commented Nov 24, 2017

Hi, I scaffold a new project with lein new serverless-cljs ok-then and cd into the directory with project.clj.

I then add one function to my core.clj like this:

(ns ok-then.core
  (:require [cljs-lambda.macros :refer-macros [defgateway]]))

(defgateway echo [event ctx]
  {:status  200
   :headers {:content-type (-> event :headers :content-type)}
   :body    (event :body)})

(defn ok []
  (println "ok"))

How can I call this function from the REPL?

@JimLynchCodes
Copy link
Author

JimLynchCodes commented Nov 24, 2017

(require 'ok-then.core)
;; => No such namespace: ok-then.core, could not locate ok_then/core.cljs, ok_then/core.cljc, or JavaScript source providing "ok-then.core"

(in-ns 'ok-then.core)
;; => ok-then.core=>
(ok)
;; => WARNING: Use of undeclared Var ok-then.core/ok_ at line 1 
;;    Cannot read property 'call' of undefined

@moea
Copy link
Member

moea commented Nov 24, 2017

@JimTheMan this plugin doesn't affect how your code is compiled or executed or anything like that - so do whatever you normally do to get a REPL going. The template doesn't include a dependency on the cljsbuild plugin - if that's what you're used to doing, maybe add that - or else you can use the cljs compiler API.

@JimLynchCodes
Copy link
Author

Thanks but this is what I normally do to get the REPL going, but it is not working- hence why I opened this issue. Can you please post how you are doing it?

@JimLynchCodes
Copy link
Author

Ah, when I cd into src directory and remove the cljs-lambda.macros then I am able to access my functions. However, I'm still unsure about other dependencies.

@JimLynchCodes
Copy link
Author

The problem is that I need to be in the src directory in order to access my namespaces, but it does not see any dependencies installed through something like lein deps.

@moea
Copy link
Member

moea commented Nov 24, 2017

@JimTheMan I'm not sure what you mean about "being in the src directory" - the REPL doesn't know what directory you're in, beyond the directory it was started in. I successfully did lein new serverless-cljs ok-then, started a REPL (M-x cider-jack-in-clojurescript in emacs), and added a var called ok - so I think whatever issue you are seeing is not related to this project / template.

Note that my ~/.lein/profiles.clj file looks like so:

{:user
 {:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
  :dependencies [[com.cemerick/piggieback "0.2.2"]]
  :plugins
  [[cider/cider-nrepl "0.15.1"]]}}

But that stuff is going to be dependent on your setup, and is just general configuration. Can you point me to another cljs project you can successfully start a REPL against? How are you starting it?

@holyjak
Copy link

holyjak commented Jan 19, 2018

I have also struggled with this. In the end I followed https://github.com/bhauman/lein-figwheel/wiki/Node.js-development-with-figwheel#nodejs-standalone-application-development-with-figwheel with some changes to keep it separate from the lambda function itself (as I only use it locally):

To my project.clj I have added

;...
:profiles {:dev {:dependencies [[org.clojure/tools.nrepl "0.2.12"]
                                  [com.cemerick/piggieback "0.2.2"]
                                  [figwheel-sidecar "0.5.14"]]
                   :cljsbuild
                                 {:builds
                                  {:dev
                                   {:source-paths ["src"]
                                    :figwheel true
                                    :compiler
                                                  {:main node-main
                                                   :output-to     "target/rbot-lambda/node-main-with-figwheel.js"
                                                   :output-dir    "target/rbot-lambda"
                                                   :target        :nodejs
                                                   :language-in   :ecmascript5
                                                   :optimizations :none
                                                   :source-map true
                                                   :pretty-print true}}}}
                   :source-paths ["dev"]
                   :repl-options {:init-ns user
                                  :nrepl-middleware
                                           [cemerick.piggieback/wrap-cljs-repl]
                                  }}}

and I have created dev/node_main.cljs with the same content as the ./server_src/figwheel4node_server/core.cljs in the guide, only with the namespace changed (figwheel4node-server.core -> node-main).

and then I run lein with-profile dev, repl and inside this Clojure REPL I start first figwheel, then the cljs REPL:

(require '[figwheel-sidecar.repl-api :as ra])
(ra/start-figwheel!)
(ra/cljs-repl)

the last thing i need to do is to start Node:

node target/rbot-lambda/node-main-with-figwheel.js

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

3 participants