This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-06
Channels
- # babashka (62)
- # beginners (52)
- # calva (37)
- # clj-kondo (23)
- # cljs-dev (13)
- # clojure (18)
- # clojure-europe (7)
- # clojure-sg (1)
- # clojure-spec (27)
- # clojurescript (37)
- # datomic (14)
- # events (2)
- # fulcro (9)
- # graalvm (12)
- # helix (1)
- # introduce-yourself (1)
- # keyboards (3)
- # lsp (3)
- # missionary (24)
- # nextjournal (7)
- # pedestal (3)
- # polylith (15)
- # re-frame (5)
- # reitit (4)
- # releases (2)
- # shadow-cljs (54)
- # testing (7)
- # uncomplicate (4)
@raymcdermott fwiw, some https://github.com/cljdoc/cljdoc-analyzer/blob/master/modules/metagetta/src/cljdoc_analyzer/metagetta/clojurescript.cljbased https://github.com/weavejester/codox/blob/master/codox/src/codox/reader/clojurescript.clj. If you want to take the static approach there is also https://github.com/clj-kondo/clj-kondo/tree/master/analysis.
I’m having trouble requiring firebase 9 sdk using the :target :bundle
approach, but I can successfully require using the :foreign-libs approach
. Here is a https://github.com/athomasoriginal/firebase-cljs. Note: I am looking to use vanilla CLJS.
• the https://github.com/athomasoriginal/firebase-cljs contains the :target :bundle
approach - does not work. :octagonal_sign:
◦ firebase throws an error Error: Component auth has not been registered yet
• the https://github.com/athomasoriginal/firebase-cljs/tree/firebase-method-2 branch contains the :foreign-library
approach - works. ✅
I don’t want to make this about firebase, because I think this is a more general issue people might run into when using JS libs using ESM.
My hunch is that it’s the way that firebase 9 sdk exports modules. They use a named module export e.g.
//------ firebase/auth.js ------
export { getAuth };
For further reference:
• https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/index.tsHaving said this. My second hunch is that they may be doing side effecting things.
might be webpack elimiating the firebase/auth
import because as far is can see it is not used?
note that this is not vanilla CLJS. figwheel seems to be doing some webpack stuff? or I just can't find where you run webpack 😛
Figwheel just automates (tmk) what you would have to do manually here: https://clojurescript.org/guides/webpack so instead of configuring :bundle-cmd
figwheel does that for you when you specify :auto-bundle :webpack
I will validate my assumption with a pure CLJS version
Yeah. Same deal.
Okay. Added a https://github.com/athomasoriginal/firebase-cljs/tree/firebase-method-4 with a pure JS example. Require statements seem to work.
Perhaps I need to try refactor the pure JS example to do exactly what CLJS does with npm_deps.js
file though? e.g.
module.exports = {
npmDeps: {
"@firebase/auth": require('@firebase/auth'),
"@firebase/app": require('@firebase/app')}
};
and then require that into the index.js file I have setup? :thinking_face:Update: https://github.com/athomasoriginal/firebase-cljs/tree/firebase-method-4 is a min repro of what cljs is doing, but in vanilla JS (assuming I understand). It seems to work just fine :thinking_face:
Okay, I think I see the problem, but my JS module foo is not strong enough to grok this ATM. When you run in JS
import { getAuth } from '@firebase/auth';
the above would import https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/index.ts#L78 which would then import https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/platform_browser/index.ts . platform_browser
is going to invoke a function called registerAuth(ClientPlatform.BROWSER);
The issue is that with how the import is happening in CLJS registerAuth
never seems to be called :thinking_face:Hi, how should I include a cljc library into a clojurescript deps.edn project using shadow-cljs? I tried including it in the :deps
of deps.edn but then shadow-cljs says the required namespace is not available. Is the general approach wrong?
I used {:local/root "../$LIBRARYNAME$"}
as described in the https://clojure.org/guides/deps_and_cli#_using_local_libraries.
if you added the dependency correctly and it is on the classpath it should just work
note that adding via :local/root
only works if the lib in question actually also has a deps.edn
Thanks, those are good pointers. It does have a deps.edn
. I'm not sure if it's on the classpath but I'll check. Do I need to build a jar for this to work?
Just checked the docs again and it doesn't require a jar. That's an even different way of including libraries.
maybe this helps https://code.thheller.com/blog/shadow-cljs/2021/05/13/paths-paths-paths.html
if you tell me which library you are trying to use and which ns I can check if it should work
This is my project setup:
├── client
│ ├── deps.edn
│ ├── shadow-cljs.edn
│ ├── [...stuff]
│ └── src
│ └── core.clj
└── csv
├── deps.edn
├── [...stuff]
└── src
└── csv.cljc
This is the client/deps.edn
:
{:deps {org.clojure/clojurescript {:mvn/version "1.10.866"}
csv/csv {:local/root "../csv"}}}
The csv lib is a bunch of functions with tests, so there's only tests in the deps.edn
:
{:aliases {:test {:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner
{:git-url ""
:sha "9e35c979860c75555adaff7600070c60004a0f44"}}
:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test}}}
This is almost exactly the same setup as in the [guide on local libs](https://www.clojure.org/guides/deps_and_cli#_using_local_libraries) but it doesn't work.Yeah, I didn't add paths, that might be it. I'll change that. Here's the Although I have :source-paths
in my client/shadow-cljs.edn
:
{:source-paths ["src"]
:dev-http {8081 "public"}
:nrepl {:port 3333}
:dependencies [[reagent "1.1.0"]
[re-frame "1.2.0"]]
:builds {:app {:target :browser
:output-dir "public/scripts"
:asset-path "/scripts"
:modules {:core {:init-fn client.core/main}}}}}
to make shadow-cljs use deps.edn you need to add :deps true
to shadow-cljs.edn and then remove :source-paths
and :dependencies