This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-12
Channels
- # announcements (1)
- # aws (1)
- # babashka (63)
- # beginners (108)
- # calva (12)
- # cider (6)
- # cljdoc (2)
- # cljsrn (33)
- # clojure (150)
- # clojure-europe (28)
- # clojure-nl (13)
- # clojure-spain (1)
- # clojure-spec (8)
- # clojure-uk (25)
- # clojurescript (16)
- # conjure (7)
- # cursive (7)
- # datomic (15)
- # duct (2)
- # eastwood (2)
- # figwheel (1)
- # figwheel-main (1)
- # fulcro (6)
- # graalvm (1)
- # graalvm-mobile (1)
- # helix (6)
- # honeysql (23)
- # integrant (6)
- # introduce-yourself (4)
- # jobs (10)
- # lsp (132)
- # malli (4)
- # meander (1)
- # membrane (1)
- # off-topic (223)
- # pathom (23)
- # pedestal (3)
- # re-frame (18)
- # reagent (13)
- # releases (1)
- # remote-jobs (2)
- # shadow-cljs (68)
- # tools-deps (217)
- # vim (19)
- # xtdb (79)
Hi I am trying to build simple node-js library and keep getting the following error when trying to use it in non-dev mode:
Cannot find module 'uuid'\\nRequire stack
my `shadow-cljs.edn` is something like:
{:deps {:aliases [:cljs]}
:builds
{:handler
{:target :node-library
:output-to "handler.js"
:exports-var example-demo.core/exports
:compiler-options {:infer-externs :auto}}
:test
{:target :node-test
:output-to "test.js"}
:autotest
{:target :node-test
:output-to "test.js"
And this only happen when I am trying this via
clojure -M:cljs:shadow release handler
My cljs file look like:
(ns example-demo.core
(:require ["uuid" :as uuid]))
(println "sample uuid: " (uuid/v4)) ;; this work properly when running in in the dev mode via REPL and check the eval the code via editor
(defn sample []
;; ... some code that return js/Promise
)
(def exports #js {:sample sample})
I am trying to read through the documentation still I am not sure if someone know if something that I may have missed?
Thanks@agilecreativity 😄 I'm seeing what you're trying to do here 😄
Hi @UJ1339K2B yeah you got me, still waiting for holy-lambda to support nodejs 😄
Nodejs support will happen in the end of the year most probably. But why not native runtime? It’s significantly faster
At work, we are heavy user of nodejs at the moment from historical reason. Since we use many library that may not work properly with Graalvm natively so that may be some issue to adopt it.
Oh I see. That’s sad ;(
Which libraries hold you in Nodejs if I could ask? Cause maybe it’s possible to interop with those via GraalVM Polyglot API
Like we are using things that talks to Redis for example, I have not yet checked if Carmine
is compatible with GraalVM for example.
but just checked it seems Carmine is compatible with GraalVM https://github.com/BrunoBonacci/graalvm-clojure/tree/master/carmine
Oh but you're mentioning now the stuff on Clojure side. I mean that in GraalVM native-image you do interop with node.js
honeq-sql should work just fine I think
@agilecreativity node builds by defaults do NOT bundle their dependencies. so whereever you run it you'll need the proper node_modules
as well
if you want something self-contained you can post-process the release file with https://github.com/vercel/ncc
Hello :) In the newest version of shadow-cljs, i think it gets confused to which node_modules folder to use dependencies. I am using deps.edn to refer to an local deps, which also contains a node_modules folder and shadow-cljs extract the js deps from the dependencies node_modules folder, which cause the build to fail as it can’t get js files outside the project. Is it a problem on my side?
The problem is resolved when I remove/rename the node_modules folder.
In the dependency lib.
only the node_modules
of your project are considered. it does not look at node_modules
of libraries, unless you specifically configured that via :js-packages-dirs
Nope, I did not such things 😕
I got the following mistakes
Build failure:
Failed to inspect file
/home/david/Documents/transparency/frontend/node_modules/@date-io/date-fns/build/index.js
it was required from
/home/david/Documents/transparency/frontend/src/cljs/transparency/reporting/user_input.cljs
files outside the project are not allowed: /home/david/Documents/transparency/frontend/node_modules/@date-io/date-fns/build/index.js
{:file #object[java.io.File 0x6910e23c "/home/david/Documents/transparency/frontend/node_modules/@date-io/date-fns/build/index.js"]}
ExceptionInfo: files outside the project are not allowed: /home/david/Documents/transparency/frontend/node_modules/@date-io/date-fns/build/index.js
While my main project is at /home/david/Documents/whatever/
Does it make sense?
in the deps.edn file, under the :deps key
transparency/transparency {:local/root "lib/transparency"}
(with a simlink)
deps.edn does not manage or affect JS depdencies in any way. so whatever you do there does NOT affect this
(:require ["@date-io/date-fns" :as date-fns-utils])
this?
I use deps.cljs under the root of the source?
of the main project?
nope, nothing
it is a plain npm i --save
As I said, if I remove the node_modules
from the dep library, it works.
this is the lib folder
/home/david/Documents/whatever
would be the project folder
Thanks a lot! Sorry for disturbing
how do i use "https" node.js standard library to make a request to an external API? If there is another library better suited for ClojureScript what would that be?
(defn book_consultation [req, res]
;/book_consultation
(let [query (.. req -query)
email (.-email query)]
(.on
(.get
https
" "
(fn [resp]
(let [data ""]
(.on
resp
"end"
(fn [] (.send res (.. (.parse js/JSON data) -results))))))
"error"
(fn [err] (.log js/console (str "Error: " (.-message err))))))))
This is the code i have, but it can't infer the target type:
--------------------------------------------------------------------------------
12 | " "
13 | (fn [resp]
14 | (let [data ""]
15 | (.on
-----------------^--------------------------------------------------------------
Cannot infer target type in expression (. resp on "end" (fn [] (.send res (.. (.parse js/JSON data) -results))))
--------------------------------------------------------------------------------
16 | resp
17 | "end"
18 | (fn [] (.send res (.. (.parse js/JSON data) -results))))))
19 | "error"
--------------------------------------------------------------------------------
could i use the cljs.core.async.macros :refer [go]
macro? Or would that not work on node.js?
I'm not the best resource to be asking, so someone can correct me if I'm wrong, but 1. if it says cannot infer target type when using a . function, I'm pretty sure it means you're missing a ^js in front of the variable in question, in your case it'd be fn [^js resp] and ^js res wherever it's declared and 2. you should be able to use macros in both browser and node.js just fine
Yes this is also what i want to use, since i already use it on the client side. Although i run into this error:
> /Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/goog/net/xmlhttp.js:177
> return new XMLHttpRequest();
> ^
> ReferenceError: XMLHttpRequest is not defined
> at goog.net.DefaultXmlHttpFactory.createInstance (/Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/goog/net/xmlhttp.js:177:5)
> at Object.goog.net.XmlHttp (/Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/goog/net/xmlhttp.js:37:36)
> at goog.net.XhrIo.createXhr (/Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/goog/net/xhrio.js:682:42)
> at goog.net.XhrIo.send (/Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/goog/net/xhrio.js:530:20)
> at Object.cljs_http$core$xhr [as xhr] (/Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/cljs_http/core.cljs:107:5)
> at cljs_http$core$request (/Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/cljs_http/core.cljs:150:5)
> at /Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/cljs_http/client.cljs:125:7
> at /Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/cljs_http/client.cljs:207:7
> at /Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/cljs_http/client.cljs:223:7
> at /Users/simonchristensen/Documents/Developer/movenation/calculator/.shadow-cljs/builds/firebase-functions/dev/out/cljs-runtime/cljs_http/client.cljs:104:7
With this code:
(defn book_consultation [req, res]
;/book_consultation
(let [query (.. req -query)
email (.-email query)]
(go (let [response (<! (http/get " "
{:with-credentials? false}))
name (get-in response [:body :results :name :first])])
(.send res (str "name is: " name)))))
It returns a XMLHttpRequest. Which makes sense, but does someone know how to call it correctly?
It works! Thank you!
(ns functions.index
(:require ["firebase-functions" :as fun]
["https" :default https]
[cljs.core.async :refer [<!]] [cljs-http.client :as http]
[cljs.nodejs :as nodejs]
["xhr2" :as xhr2])
(:require-macros [cljs.core.async.macros :refer [go]]))
(set! js/XMLHttpRequest xhr2)
(defn book_consultation [req, res]
;/book_consultation
(let [query (.. req -query)
email (.-email query)]
(go (let [response (<! (http/get " "
{:with-credentials? false}))
name (get-in response [:body :results 0 :name :first])]
(.send res (str "name is: " name))))))
yeah I just thought it would be more clear if i declare all the imports in require. I am aware i could write (set! js/XMLHttpRequest (nodejs/require "xhr2"))
Also as a side note, I really have to compliment the response time of @thheller and @borkdude, the speed and amount of support you both give is amazing, as are your projects! I've been using babashka and shadowCLJS for a while now and I never knew both of you were so accessible hahaha In any case, thank you for your hard work, it's appreciated!
I’m running the tests like so: shadow-cljs release test and this is my config file:
{:nrepl {:port 7002}
:builds
{:app
{:target :browser
:output-dir "target/cljsbuild/public/js"
:asset-path "/js"
:modules {:app {:entries []}}
:devtools {:watch-dir "resources/public"
:preloads [re-frisk.preload]}
:dev {:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}}
:release {}}
:test {:target :node-test
:test-dir "target/node-tests.js"
:autorun true
}}
:lein true}
And I’m getting this error:
https://gist.github.com/zendevil/6f29c2ac64d8be067e5e5f525b2f059e
How can I fix this?@ps I'm guessing target/node-tests.js
is an actual file? when it should be a directory?
this is a snippet from the user guide:
{...
:builds
{:test
{:target :node-test
:output-to "out/node-tests.js"
:ns-regexp "-spec$"
:autorun true}}}