Fork me on GitHub
#clojurescript
<
2021-11-06
>
athomasoriginal15:11:41

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.ts

athomasoriginal15:11:44

Having said this. My second hunch is that they may be doing side effecting things.

thheller15:11:08

might be webpack elimiating the firebase/auth import because as far is can see it is not used?

thheller15:11:12

although unlikely given that is can't see anything else either

thheller15:11:42

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 😛

athomasoriginal15:11:10

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

athomasoriginal16:11:06

I will validate my assumption with a pure CLJS version

thheller16:11:36

well if its just be basic thing it should be fine

athomasoriginal16:11:18

Yeah. Same deal.

dnolen18:11:29

Maybe try repro without CLJS? I guess it’s the require from CLJS that causes this?

athomasoriginal18:11:02

Okay. Added a https://github.com/athomasoriginal/firebase-cljs/tree/firebase-method-4 with a pure JS example. Require statements seem to work.

athomasoriginal18:11:45

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:

athomasoriginal19:11:03

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:

athomasoriginal17:11:46

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:

genRaiy18:11:58

@lee thanks for the pointers, I would prefer the non-static approach for the moment

👍 1
Gerome20:11:46

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?

Gerome20:11:09

I used {:local/root "../$LIBRARYNAME$"} as described in the https://clojure.org/guides/deps_and_cli#_using_local_libraries.

thheller07:11:24

if you added the dependency correctly and it is on the classpath it should just work

thheller07:11:47

note that adding via :local/root only works if the lib in question actually also has a deps.edn

Gerome08:11:50

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?

Gerome11:11:31

Just checked the docs again and it doesn't require a jar. That's an even different way of including libraries.

thheller14:11:19

explaining classpath and so on

thheller14:11:53

if you tell me which library you are trying to use and which ns I can check if it should work

Gerome14:11:48

Thanks! I'll take a look at the doc. It's lib I wrote myself.

Gerome14:11:17

I'm on my phone right now but I'll try it again when I'm at my computer tonight.

thheller14:11:22

then assuming all paths are correct it should work

Gerome14:11:28

I'll double check the paths

Gerome20:11:15

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.

thheller20:11:52

I don't see any :paths?

thheller20:11:21

also don't see shadow-cljs?

Gerome20:11:40

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}}}}} 

thheller20:11:06

so you are not actually using deps.edn.

💡 1
thheller20:11:35

to make shadow-cljs use deps.edn you need to add :deps true to shadow-cljs.edn and then remove :source-paths and :dependencies

thheller20:11:53

those will then be mananged via deps.edn so you need to add them there as well as shadow-cljs itself

Gerome20:11:55

That makes total sense. Thanks!