This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-02
Channels
- # announcements (2)
- # babashka (16)
- # beginners (48)
- # biff (5)
- # calva (21)
- # cider (9)
- # clerk (24)
- # clj-kondo (43)
- # clj-otel (3)
- # clj-yaml (44)
- # cljdoc (13)
- # cljs-dev (2)
- # cljsrn (7)
- # clojure (39)
- # clojure-dev (21)
- # clojure-europe (18)
- # clojure-hamburg (1)
- # clojure-losangeles (1)
- # clojure-norway (24)
- # clojure-sweden (4)
- # core-typed (3)
- # cursive (7)
- # data-science (10)
- # datalevin (7)
- # datomic (49)
- # emacs (7)
- # events (2)
- # graalvm (7)
- # hyperfiddle (56)
- # integrant (10)
- # jobs-discuss (29)
- # leiningen (27)
- # lsp (12)
- # malli (3)
- # off-topic (13)
- # polylith (18)
- # reagent (13)
- # sci (49)
- # shadow-cljs (94)
- # sql (3)
- # squint (2)
- # vscode (5)
- # xtdb (17)
i'm having with the following npm library:
(:require ["@onefootprint/footprint-js" :as footprint])
when i print footprint
, it's just an empty js object. the library is not public so i can't link to the source, but this is what it looks like in node_modules (screenshot).
i also need to do the equivalent of this: import '@onefootprint/footprint-js/dist/footprint-js.css';
which throws an errorhmm looks like the screenshot isn't loading, i'll try attaching it again here
shadow-cljs does not support css, therefore requiring a css file won't work. you'll need a secondary tool for that
gotcha, thanks! how about the main library import? is that type of import not supported?
and this is the actual file that is getting included? I see a .cjs
file. what does the package.json "main"
entry say
"./dist/footprint-js.umd.js"
- ah yeah sorry, screenshotted the wrong file
it has exports:
"exports": {
".": {
"require": "./dist/footprint-js.umd.js",
"import": "./dist/footprint-js.js",
"types": "./dist/footprint-js.d.ts"
},
"./dist/footprint-js.css": {
"import": "./dist/footprint-js.css",
"require": "./dist/footprint-js.css"
}
},
ok, so in that case shadow-cljs will follow the require by default. you can change this by setting
:export-conditions ["browser" "require" "default" "module" "import"]
in the build configit is weird that the require
is pointing to a umd.js
file. that seems uncommon to me, would expect the .cjs
there.
does :export-conditions
go in the :js-options
map?
if you are on an older version then "exports"
is not considered. only the other top level keys, so "browser"
or "main"
or "module"
oh haha. it's ok, this is from a vendor we're working with so i can try asking them for a cdn instead
which you can also change by re-ordering :entry-keys ["browser" "main" "module"]
, to move module to first
but that only works for requires that you control yourself, so if something else still requires "@onefootprint/footprint-js"
then you'll still have the problem
oh yeah i tried that first and got ExceptionInfo: package @onefootprint/footprint-js had exports, but could not resolve ./dist/footprint-js.js
i'm on 2.24.1
i tried the :export-conditions
and it seemed to mess with the import of a different library
well ideally the package just removes the .umd.js file from require, that is uncommon and not something I have seen before
this is what's in the file:
(function (exports) {
'use strict';
...bunch of stuff here
exports.FootprintInternalEvent = w;
exports.FootprintPublicEvent = E;
exports.default = Nt;
exports.identifyUser = W;
Object.defineProperty(exports, '__esModule', { value: true });
return exports;
})({});
otherwise that file is rather useless since the return value is never used? (which is also why you are seeing an empty object when printing the variable)
hmm not that i can see
tysm for the insight. fortunately vendor is amenable to a cdn
I don't recommend using cdn versions though 😉 easier to just either use the .js or .cjs files 😛
how would we use the js file? change the package.json?
the library is on npm btw https://www.npmjs.com/package/@onefootprint/footprint-js?activeTab=code
oh wow you're right haha, just realized it was actually another one (footprint-react) that wasn't online
changing the package.json "main" and "require" totally worked
the issue likely is that webpack and most other JS tools nowadays default to using the "module"
or exports/import
key
but would be impractical to do that after every npm install
shadow-cljs still defaults to the older default and thats why you end up with the require and umd file
in your opinion would it be reasonable to ask the devs to change the package.json permanently?
in my opinion the umd file is invalid and unusable, so yes someone should look into that. also pointing the "require"
key at the umd file will make the entire thing unusable in node
Errors encountered while trying to parse file
/Users/elle/local/composer/composer-web/node_modules/htmlparser2/lib/esm/index.js
{:line 48, :column 9, :message "'from' expected"}
is there shadow support for resolving local-only deps?
yeah, ~/.m2/repository
if you mean “local deps” as in deps.edn’s :local/root
then you will need to manage dependencies with a deps.edn alias and set :deps
in shadow-cljs.edn
to the alias
unless I missed an option, that throws a DependencyResolutionException
bc it looks on central and doesn't find anything
it is, I just put it there. It's a library I'm working on, so its at ~/.m2/repository/bhlie/<my-lib>.jar
the structure of the local repo is something like this
.m2/
repository/
group/
artifact/
version/
_remote.repositories
artfiact-version.pom
artfiact-version.jar
...
yeah, I'm learning that as we speak 😅
so once I've made the jar, I should do mvn install
in the project directory and that will put everything I need in ~/.m2
tools.build
remove the GAV from your :dependencies
then drop the JAR file into somewhere like a resources
folder… and in your shadow-cljs.edn file, add resources
to your :source-paths
maybe?
the idea behind this approach is to try adding the JAR to your classpath manually, and avoid having to install to an m2 repo
oh cool yeah I was thinking of something along those lines but e.g. java -cp
only I didn't know how to make that work with shadow
I'll give that a go
worst case scenario, we can just manually install the JAR with maven by doing something like
mvn install:install-file -Dfile=your.jar -DgroupId=group -DartifactId=artifact -Dversion=version -Dpackaging=jar
but warning: I have not tested thisShould I be able to require
this like any other source once it's on the classpath? I expect yes but I'm evidently doing something wrong
well, I was gambling on shadow-cljs adding anything on the :source-paths
to the classpath… but that doesnt seem to be the case if this doesnt work
nice, that worked!