This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-22
Channels
- # announcements (2)
- # beginners (137)
- # chlorine-clover (13)
- # clj-kondo (3)
- # cljsrn (4)
- # clojure (52)
- # clojure-australia (3)
- # clojure-dev (2)
- # clojure-europe (34)
- # clojure-nl (1)
- # clojure-sg (3)
- # clojure-spec (1)
- # clojure-uk (12)
- # clojurescript (2)
- # clojureverse-ops (7)
- # code-reviews (3)
- # conjure (2)
- # cursive (18)
- # datavis (21)
- # datomic (34)
- # exercism (1)
- # figwheel-main (6)
- # graphql (3)
- # helix (21)
- # introduce-yourself (1)
- # jackdaw (1)
- # jobs (4)
- # jobs-discuss (32)
- # juxt (14)
- # leiningen (6)
- # lsp (35)
- # meander (19)
- # nrepl (2)
- # off-topic (37)
- # portal (40)
- # quil (5)
- # re-frame (45)
- # reagent (10)
- # releases (1)
- # remote-jobs (4)
- # reveal (15)
- # sci (7)
- # shadow-cljs (40)
- # spacemacs (3)
- # tools-build (2)
- # vim (17)
- # xtdb (11)
I'm trying to deploy my app to heroku and I keep getting this error: The required namespace "react" is not available, it was required by "reagent/core.cljs".
But I have "react": "17.0.2-0", "react-dom": "17.0.2-0", "react-highlight.js": "1.0.7", all in my package.json and I also put [cljsjs/react "17.0.2-0"] [cljsjs/react-dom "17.0.2-0"] in my project.clj. I also did npm install react. I'm not sure what I'm doing wrong?
Are you using a bin/build
file to add extra instructions? Mine looks like this:
#!/usr/bin/env bash
npm install
npx shadow-cljs release app
clojure -X:uberjar :jar ai.jar
as I have a clojure backend too. Do you have both the clojure and node buildpacks installed?I used some of the advice from here: https://folcon.github.io/post/2020-04-12-Fulcro-on-Heroku/ even though I'm not using fulcro and also got some help here on slack.
Thanks @U9J50BY4C . Is a bin/build file, just a file with that name and no extension?
I'm a total newbie and trying to google "bin/build" file but not getting much results about it 😕 Or is it a file called build in the bin folder?
I'm also not sure if I have all the buildpacks installed. How do I check for that? Thanks again for the help @U9J50BY4C
Yeah the file itself is just called build
and you put it in a bin
folder. Check out that link I gave you above for an example and it also explains how to add multiple buildpacks
Thanks again. For some reason I'm getting the same error The required namespace "react" is not available, it was required by "reagent/core.cljs" after making adding the build file. I'll keep looking through the links and see what happened. I am using lein
I don't think I'm using nodejs. Or because I'm using Reagent and react does that mean I am using nodejs? I get errors when I use that buildpack
Do you want to share your repo? I think you will need node. Make sure you have the node buildpack first, then the clojure one.
λ ~/projects/clojure/ai : heroku buildpacks
=== ai-marketing-copy Buildpack URLs
1. heroku/nodejs
2. heroku/clojure
Hi @U9J50BY4C Here is my repo: https://github.com/johnbradens/kewl-app Sorry if it's a mess
I did run chmod u+x bin/build, and the buildpack commands that are in the blog post you sent from Alien Brain
I copied the bin/build file exactly as in the blog post, but I'm not sure if I should have changed it at all for my own project... I also added the line to shadow-cljs.edn that it said. But, I don't have a deps.edn so I didn't make that change that was in the blog.
Thanks again for helping, I really appreciate it @U9J50BY4C !
And yeah since you are using lein, that bin/build
file (which I did not see in your repo) should have something like lein uberjar
instead of clojure -X:uberjar :jar ...
like I have in mine.
I too started with the big ole luminus framework and just couldn't wrap my head around it, including getting it deployed. Unfortunately the long conversations I had with others have already been archived and it's a struggle finding such things in the slack archive.
Thanks @U9J50BY4C I get some warnings but the build does complete successfully. I think you're right about the lein uberjar. I replaced the other line with lein uberjar but it's still not working. 😕
I also wish it was easier to find archived messages on here
I might ask again in some of the other channels and crowdsource some more ideas
Definitely. I know it's frustrating. I can't remember if I eventually got it working with leiningen/luminus before deciding to start from scratch and learn without a template.
Is the nodejs buildpack listed first? I feel like it is calling your clojure code before compiling the clojurescript code so the cljs hasn't been compiled down to js yet and thus not finding react. These are just wild guesses from my part though, I'm pretty newbish myself.
Another wild guess from me is maybe take out that :prep-task
command in your :uberjar
alias of your project.clj
config. That bin/build
file is doing the npm install and shadow-cljs release app
so maybe trying to call it again when compiling your clojure into an uberjar is messing things up.
The other option here if you can't get this working is building this all in a docker file and just uploading that docker build to heroku. That is what a couple others ended up doing when I was asking them. I don't know docker though so I found my way and ran with that.
Turns out I had the clojure buildpack listed first. Now I just changed it to be nodejs listed first, and I get an error that I need to do npm install before continuing because the package.json and package-lock.json are not in sync. It says " npm ERR! Missing: [email protected] remote: npm ERR! Missing: [email protected] " but I can see them in both files :thinking_face: Is it correct to have nodejs first, or clojure first? I seem to get different errors depending on which one I do.
I'll look into Docker too. And I'll take out the :prep-task command right now and see if that helps.
Thanks again!
#!/usr/bin/env bash
npm install
npx shadow-cljs release main
lein uberjar
looks right to me. Nodejs buildpack should be first. When you push to heroku does it say something like "detected bin/build
file so using those instructions" or whatever?
No it doesn't actually...
I do
git push heroku main
And then I get
Enumerating objects: 173, done.
Counting objects: 100% (173/173), done.
Delta compression using up to 4 threads
Compressing objects: 100% (150/150), done.
Writing objects: 100% (173/173), 510.65 KiB | 7.40 MiB/s, done.
Total 173 (delta 17), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpacks:
remote: 1. heroku/nodejs
remote: 2. heroku/clojure
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 14.x...
remote: Downloading and installing node 14.17.6...
remote: Using default npm version: 6.14.15
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote: npm ERR! cipm can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
remote: npm ERR!
remote: npm ERR!
remote: npm ERR! Missing: [email protected]
remote: npm ERR! Missing: [email protected]
remote: npm ERR!
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.CuKJM/_logs/2021-09-22T22_59_41_912Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here
remote:
remote:
remote: Some possible problems:
remote:
remote: - Node version not specified in package.json
remote:
remote:
remote: Love,
remote: Heroku
In the root directory, I have a bin folder and then the build. I just realized, I might want it somewhere else right?
When I run that command, nothing happens
Where would I see the asterisk?
Oh I see. I am just using my terminal window on a mac. I use Emacs but haven't figured out how to run terminal commands from there yet or set up the nice file trees...
Do you think I should be getting something instead of no output?
I'll try sudo
Ok great. I did sudo too, and it asked for my password, but same effect. Thanks again.
And just to confirm, you have done something like git add .
and git commit -m "added bin/build file"
before doing this push right?
I don't think I did the "added bin/build file"
Thanks for checking. Do I have to re-do git add now? I did the git add and git commit before adding the bin/build file
Sorry if this is too many basic questions
Thanks so much. I'll try that right now.
Wow so the whole time I was making changes, heroku had no idea 😅
It is running now. I saw it says running bin/build. Yay!
Just to prepare you, even if this compiles correctly there is a chance you don't see anything show up on your deployed site. That is because Heroku also requires you to pull in their own port
while you might have just hard set one in your code.
Ok thank you!!!
Did ya get it working @U02387J8EKG?
Thanks for checking in @U9J50BY4C. I'm getting the error Error: Could not find or load main class"
Do you know what main it is referring to? I have main in my project.clj file, and in my build it said "shadow-cljs release main". I tried changing it to release app, because in my build map in shadow-cljs.edn it says app instead of main, but I still get the same error.
I'm going to try changing the shadow-cljs.edn file to say main instead of app
That should actually be from the java side of things I think if it is talking about a class
It compiles fine using shadow-cljs to my localhost, but it won't compile when I try to push to heroku. Any idea what I'm missing?
Hi, I am using luminous and trying to use honeysql. I have a queries namespace in which I require db using (:require [shopmap-server.db.core :refer [db]). I also have a line of code that is supposed to pring db, but it prints "object dereferable state..." whereas in the repl it prints what I need which is the object containing a hikari datasource. Could someone please help me out? Thanks!
@zengxh I tried, and it errors since the status is pending and the value is nil
It seems to me like the database connection is not actually being loaded or something, but I do not know enough about how clojure works in that sense
Sorry I hsould have mentioned that I have tried to deref the variable
yes it is. should it be as?
if so, I will google why
do you see db/xyz
in the same .clj file where you use (:require [shopmap-server.db.core :refer [*db*])
?
this is something I am adding in since luminous uses hugsql and binds a file, not honey. My idea was that I can have a queries file with my honeysql queries and use the db object that is returned from the state
creating functions that execute the queries on a connection I get using (.getConnection db ). Before that, I had connected using jdbc/get-datasource with a config defined in the same file, but I am trying to remove the config from the code
currently the code looks like(with sensitive info removed):
(ns shopmap-server.routes.queries.user
(:require [honeysql.core :as sql]
[shopmap-server.db.core :refer [*db*]]))
(println *db*)
When printed in the terminal from lein test-refresh, I get "#object[mount.core.DerefableState addr {:status :pending, :val nil}] whereas when I print it from the nrepl, I get the actual object
oh i get it. it's the db part changed to bold by the editor. then you refering *db*
is alright.
yes sorry
my *db*
evals to #object[com.zaxxer.hikari.HikariDataSource 0x5415ef3e "HikariDataSource (HikariPool-1)"]
yeah that's what mine evals to in the repl
so I think I'm doing that part right, which is why I'm a bit confused why it doesn't eval to that in lein test-refresh...
it's causing all of my queries to fail basically because the thing is nil
which file? the test file?
my test file is at /test/clj/shopmap_server/handler_test.clj
you'll see in there the db is started for the test while in handler the db is not started
there is no file in the db
I should be able to see one in a luminous example online though right?
I'm sure I"ll find it. Thank you!
(ns guestbook.db.core-test
(:require
[guestbook.db.core :refer [*db*] :as db]
[java-time.pre-java8]
[luminus-migrations.core :as migrations]
[clojure.test :refer :all]
[next.jdbc :as jdbc]
[guestbook.config :refer [env]]
[mount.core :as mount]))
(use-fixtures
:once
(fn [f]
(mount/start
#'guestbook.config/env
#'guestbook.db.core/*db*)
(migrations/migrate ["migrate"] (select-keys env [:database-url]))
(f)))
(deftest test-messages
(jdbc/with-transaction [t-conn *db* {:rollback-only true}]
(is (= 1 (db/save-message!
t-conn
{:name "Bob"
:message "Hello, World"}
{:connection t-conn})))
(is (= {:name "Bob"
:message "Hello, World"}
(-> (db/get-messages t-conn {})
(first)
(select-keys [:name :message]))))))
in luminus framework there're at least the env, db, http-server components started by mount
in your /test/clj/shopmap_server/handler_test.clj probably just add db to the use-fixtures
I bet that's the problem. I am adding it now, will update in a second
that would make complete sense though
it works! thank you so much
It was a bit confusing to me that they have multiple test files, one in db and one in handler. I should have looked through the test file and seen that the database state was not being loaded. I knew that it wasn't being loaded, but didn't realize it was such a simple thing for me to miss. Thank you so much again, saved me a ton of time, I'll read through more carefully next time haha
Saved me a ton of time
Is there a shorter way to do this?
(let [foo (fn [x y z]
{:x x :y y :z z})]
(map (fn [coll] (apply foo coll)) [[1 2 3]
[4 5 6]]))
(letfn [(foo [[x y z]]
{:x x :y y :z z})]
(map foo [[1 2 3]
[4 5 6]]))
Also
(map #(zipmap [:x :y :z] %) [[1 2 3]
[4 5 6]])
I'm using the replace function, but I actually want values to be replaced with nil if they aren't in the map (instead of identity). I figure there's a simple way/different function that will do that?
the nil
here is redundant
yes, that too
just (map {:a :A :b :B} [:a :b :c :d])
maps are functions so you can just map the map 🙂
@UH13Y2FSA in case you're not aware, sometimes the juxt
function is useful for this:
user=> ((juxt :a :b :c :d) {:a :A :b :B})
[:A :B nil nil]
there's also replace
if you want the original value if it wasn't in the map
the juxt
version above requires that the items in the original collection are invocable which isn't true for collections in general