This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-04
Channels
- # beginners (90)
- # boot (5)
- # cider (89)
- # cljsrn (27)
- # clojure (33)
- # clojure-dev (2)
- # clojure-italy (3)
- # clojure-spec (35)
- # clojure-uk (17)
- # clojurescript (93)
- # code-reviews (1)
- # datascript (2)
- # datomic (14)
- # defnpodcast (6)
- # emacs (11)
- # figwheel (8)
- # figwheel-main (6)
- # hyperfiddle (14)
- # jobs-rus (1)
- # nrepl (3)
- # off-topic (13)
- # onyx (6)
- # reagent (6)
- # reitit (4)
- # shadow-cljs (110)
- # spacemacs (1)
- # tools-deps (10)
- # vim (17)
is there a complete example on how to use imported npm modules with a clojurescript app? I used lein new macchiato
and am trying to use the google compute module that installs as npm install --save @google-cloud/compute
and imports as const Compute = require('@google-cloud/compute');
. I tried adding :npm-deps {"@google-cloud/compute" "0.10.0"}
but I am getting:
No such namespace: @google-cloud/compute, could not locate _CIRCA_google_cloud_SLASH_compute.cljs, _CIRCA_google_cloud_SLASH_compute.cljc, or JavaScript source providing "@google-cloud/compute" (Please check that namespaces with dashes use underscores in the ClojureScript file name)
any tips, my searches are not turning up this use case for some reason...I also tried:
:foreign-libs [{:file "node_modules/@google-cloud/compute/src/index.js"
:provides ["gcp"]} ]
Hmmm no, do I specify that in the compiler section? But I did install it manually with npm
Well, then that might not be it. I’m inferring that it might be required from https://anmonteiro.com/2017/03/requiring-node-js-modules-from-clojurescript-namespaces/
For anybody able to help, I’ll post mine as well. I’m trying to integrate https://emotion.sh/ using :npm-deps
. It gets past the compiler, but fails to render and sends Undefined nameToPath for module$create_emotion
to the JS console from inside goog/base.js
I suspect that means I need to write some externs (?) but haven’t figured out how to do that or how to tell the compiler about it in this scenario
@b-paul it seems to have gotten me further but getting weird errors $module$_CIRCA_google_cloud$compute.Compute is not a constructor
and can require it from the repl
(ns gcp-bot.routes
(:require
[bidi.bidi :as bidi]
[hiccups.runtime]
[macchiato.util.response :as r]
["@google-cloud/compute" :as gcp]
)
(:require-macros
[hiccups.core :refer [html]]))
(defn home [req res raise]
(let [
compute (gcp/Compute.)
zone (.zone compute "us-central1-a")
name "ubuntu-http"
vm (.createVM zone name (clj->js {:os "ubuntu"}))
])
(-> (html
[:html
[:head
[:link {:rel "stylesheet" :href "/css/site.css"}]
]
[:body
[:h2 "Hello World! v3"]
[:p
"Your user-agent is: "
(str (get-in req [:headers "user-agent"]))]]])
(r/ok)
(r/content-type "text/html")
(res)))
dev:cljs.user=> (:require ["@google-cloud/compute" :as gcp])
---- Compiler Warning on <cljs form> line:1 column:40 ----
Use of undeclared Var cljs.user/gcp
1 (:require ["@google-cloud/compute" :as gcp])
^---
---- Compiler Warning ----
how would one make something like this compile w/o warnings against 1.9.660+ (Warn on variadic signatures in protocol method implementation)?:
IFn
(-invoke [this & args]
(apply assoc this args))
I'd like to use a library that depends on at least v1.10 of cljs but my program depends on a library that depends on something that depends on a library that depends on a function that's been deleted since 1.9.874. I tried recompiling against that library with every of its dependencies upgraded to "LATEST" but I'm still getting the error. Has anyone developed a tool to walk the dependencies of your application to find such things?
@U2BL1A092 You could turn off that particular warning
Also, if you use the :aot-cache
feature, a consequence is that once code is compiled and cached, you don’t see the same warning over and over again
@mfikes its not a warning. Its a fatal error due to a missing function.
Thanks @U06B8J0AJ. Yes, my problems rarely seem simple 😕 (or at least those are the only memorable ones). I'll check it out
@U2BL1A092 This is just a warning, if it is the same thing you are seeing.
cljs.user=> (deftype Foo []
#_=> IFn
#_=> (-invoke [this & args]
#_=> (apply assoc this args)))
^
WARNING: Protocol IFn implements method -invoke with variadic signature (&) at line 1
cljs.user/Foo
yeah, no its
adzerk.boot_cljs.util.proxy$clojure.lang.ExceptionInfo$ff19274a: Invalid :refer, var cljs.reader/reader-error does not exist in file /home/kevin/.boot/cache/tmp/home/kevin/0work/newtest/kqe/n5ob01/index.html.out/tailrecursion/priority_map.cljs
tag: :cljs/analysis-error
reader-error's been deleted but the version of priority-map that my library depends on is too old and still tries to call it
@U06B8J0AJ I see nothing in google for clojure-stree nor clojure stree
oh, I see it. Its an option to clj. Yeah, it was returning a bunch of results for clojure "street"
@U2BL1A092 The fix is in place https://github.com/tailrecursion/cljs-priority-map/commit/51c29f4592dfd8ab3acd121f2f6fd4c5cc18e886
So you could specify version 1.2.0
of cljs-priority-map
(Looks like 1.2.1
is actually the latest.) https://clojars.org/tailrecursion/cljs-priority-map
the problem is its not my code that calls it, nor the library I'm using, but something that library's calling
like I said, I changed all the dependencies of the library I'm calling to LATEST and the bug still showed up
In either case, check to ensure you are using 1.2.0
or 1.2.1
and that 1.1.0
isn’t on your classpath
I'm using boot
I don’t have experience with boot, but I suspect it would amount to putting [tailrecursion/cljs-priority-map "1.2.1"]
in your dependencies specification
its the hoplon/ui library that's pulling in cljs-priority-map
well, actually its pulling in something that's pulling that in
and its pulling in like 1.0.3
ok, I'll try that
hey, that seems to have worked! I put that dep in the hoplon/ui build.boot. Thanks!
for future such issues, you have any idea how to use -Stree from within boot to list cljs deps?
IIRC boot has a way to display the calculated classpath and I suspect it has a way to display the full dependency tree.
Hello all! Is there an option with the newest clojurescript to require build-in nodejs module like fs
inside the ns
?
Doesn’t have to be built in either, I’m using…
["@material-ui/core" :refer [Menu MenuItem]]
… to access Material UI components in a #reagent based app, for example.I am using the figwheel
. Here is how my ns looks like:
(ns streams-vs-channels.seeder
(:require [cljs.nodejs :as nodejs]
[goog.string.format]
[goog.string :as gstring]
[clojure.core.async :as async]
[fs :as fs]))
And I am receiving the following error:
Figwheel: message from client couldn't be read!
As I can see the cljs is unable to detect the node build-in modulesAh! Right. This all being said, I’ve never figured out how to get it to work in vanilla CLJS tools, only in #shadow-cljs .
Thank you @U06B8J0AJ. I think that in vanilla CLJS it's not possible 🙂
I will use goog.provide then 🙂
Either way, I’d recommend giving shadow-cljs a go. It’s a 5 minute set up or so, and it removes quite a few headaches.
Doesn’t affect your deps.edn
or project.clj
, so you can safely try it out in parallel.
@U9ARBCP5K Yes, you can do this in vanilla ClojureScript. We recently fixed https://dev.clojure.org/jira/browse/CLJS-2724 so perhaps you are missing that fix.
I am using the newest CLJS [org.clojure/clojurescript "1.10.339"]
Yes I do have:
:cljsbuild
{:builds
{:dev {:source-paths ["src"]
:figwheel true
:compiler {:output-to "bundle/bundle.js"
:main streams-vs-channels.core
:libs ["src/foreign"]
:target :nodejs
:optimizations :none}}}})
Ok it works with
(require 'fs)
(.log js/console fs)
But does not work in (ns)
Ok so maybe it's a problem with a regular figwheel
Let me see if I can repro with regular figwheel… I think this project used to be based on regular figwheel…
@mfikes I really appreciate your help.
@U9ARBCP5K Yeah, a :require
of fs
works for me in an older version of that project that uses regular figwheel
@mfikes could you please share your project.clj and the part of code in which you’re requiring the fs module?
I’m going to try it with https://github.com/bhauman/lein-figwheel/wiki/Node.js-development-with-figwheel#nodejs-standalone-application-development-with-figwheel which anyone can repro
@U9ARBCP5K ^ that works (updating to latest deps
Could you please share the project clj? I think that this causes the problem ;(
@mfikes It's a problem with the cider itself I think.
With the latest cider when I try to evaluate the ns with cider-eval-last-sexp
then I got that error but in the figwheel console the module is correctly imported 🙂 Error occurs only in the repl.
Could you please confirm whether you experiencing the same issue? If so I will create the issue on cider's github and I will try to fix it.
@U9ARBCP5K I don’t use emacs
@mfikes Thank you for all your help I will try to debug that error in the emacs 🙂
@U9ARBCP5K I don't know if this will help, but I've noticed that just loading a file (with namespace and resources) via figwheel typically does not make it 'really' available via repl in cider. You need to (cljs-repl) and then go to buffer and do a C-c C-k (compile buffer) to get everything workable from cider as well as figwheel. Or for this you would need to at least eval the namespace. I have no idea why this is true, but it is. Caveat: I'm on Cider and cider-nrepl 0.17.0
@sjol This seems to be working
$ clj -m cljs.main -co '{:npm-deps {"@google-cloud/compute" "0.10.0"} :install-deps true}' -re node -r
ClojureScript 1.10.339
cljs.user=> (require '["@google-cloud/compute" :as Compute])
nil
cljs.user=> (def compute (Compute.))
#'cljs.user/compute
cljs.user=> (.zone compute "us-centrall-a")
#object[Zone [object Object]]
Hello all, if I use in react import { something } from 'something-else';
-> (def Something (js/require "something-else"))
, what would be use for import something from 'something-else';
?
@fabrao cool. I suspect this ticket is about the same https://dev.clojure.org/jira/browse/CLJS-2376
@bhauman Thank you sir for Figwheel and Devcards!