This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-24
Channels
- # announcements (8)
- # babashka (16)
- # beginners (18)
- # biff (4)
- # calva (18)
- # clj-kondo (20)
- # clojure (24)
- # clojure-brasil (1)
- # clojure-europe (13)
- # clojure-nl (1)
- # clojure-norway (35)
- # clojure-uk (3)
- # clojurescript (16)
- # core-async (50)
- # cursive (5)
- # data-science (5)
- # datalevin (5)
- # datomic (69)
- # dev-tooling (18)
- # fulcro (3)
- # gratitude (1)
- # honeysql (5)
- # hyperfiddle (4)
- # jackdaw (2)
- # jobs-discuss (24)
- # lambdaisland (7)
- # lsp (16)
- # malli (5)
- # off-topic (65)
- # overtone (16)
- # pathom (28)
- # portal (3)
- # re-frame (24)
- # releases (1)
- # shadow-cljs (101)
Another exports question: is the case of a vector value supported? For instance
"./*": ["./dist/src/*", "./dist/src/*.js"]
The intent is that ./foo
causes a search for ./dist/src/foo
first then ./dist/src/foo.js
I am trying to work around an issue where I am using a javascript library that inconsistently uses fake paths, sometimes without .js extensions, other times with a .js extension. 😛
The interesting part is that every bundler I have tried handles it gracefully, but shadow doesn’t. Not shadow’s fault, though. There is next to zero documentation on how this exports key should work anyway
exports are usually only used for external lookups, i.e. requests from outside the package?
Ok, so there are two libraries at play. Library A has exports
{"./*": "./dist/src/*.js",
"./*.js": "./dist/src/*.js"}
Library B depends on library A. Some files in library B use
import { thing } from "@A/foo";
Some files in library B instead use
import { thing } from "@A/foo.js";
Library A has an invalid exports entry, based on the explanation youve provided me in an earlier thread. So I decided to experiment using the array syntax at the start of this thread, in attempt to “fix” the exports declared in library A’s package.json
At the moment, I decided to bite the bullet and manually refactor library B so that it consistently refers to files without extension. Now shadow can locate the files. (Just barely tested npx shadow-cljs compile app
and it succeeded after refactoring about two dozen imports in library B)
(I also didn't check a whole lot of package, basically only those users reported not working)
Unfortunately these libraries are company-internal libraries, but I can easily make a minimal project reproducing this issue I’ve faced. It’s just a matter of whether its worth supporting or not (probably not, since this is the first time I’ve ran into a JS library with huge inconsistencies in imports)
I mean I wasn't sure when I wrote it and changing that to str/includes?
is not a big deal
oh these two libraries in question are some of the messiest typescript Ive ever seen
to make things play nicely with shadow I went and set up bundlers since they are doing all sorts of crazy things, like importing JSON files with an assert
keyword that google-closure doesnt support
originally they simply ran tsc
and the outputted JS didnt even work in Node.js or Chrome… let alone shadow and gcc. the tsconfigs have references and path aliases all over the place.
in any case, I managed to solve the problem I was facing — shadow’s existing functionality is sufficient for my needs
yeah people never pick up any discipline when webpack basically allow all sorts of random combinations 😛
Sorry it took a while — here is a repro https://github.com/rome-user/shadow-exports-repro
https://github.com/thheller/shadow-cljs/commit/b3e22dada45389bff47ac3e788d97515b5eca2bb
or did you just try that because
{"./*": "./dist/src/*.js",
"./*.js": "./dist/src/*.js"}
didn't work?But tsc, tsup, rollup, vite, etc. all handle
{"./*": "./dist/src/*.js",
"./*.js": "./dist/src/*.js"}
gracefullycan you give it a quick test? Just paste this into your REPL and let shadow compile?
package A had exports, but could not resolve ./foo.js
{:package #object[java.io.File 0x12f76ddf "/Users/****/Desktop/repro/packages/B/node_modules/A"], :require-from [:shadow.build.npm/resource "node_modules/B/src/two.js"], :rel-require "./foo.js"}
ExceptionInfo: package A had exports, but could not resolve ./foo.js
shadow.build.npm/find-resource-in-package (NO_SOURCE_FILE:907)
shadow.build.npm/find-resource-in-package (NO_SOURCE_FILE:888)
shadow.build.npm/find-resource (NO_SOURCE_FILE:1027)
shadow.build.npm/find-resource (NO_SOURCE_FILE:951)
shadow.build.resolve/find-npm-resource (resolve.clj:123)
shadow.build.resolve/find-npm-resource (resolve.clj:94)
https://github.com/rome-user/shadow-exports-repro/blob/master/packages/A/package.json#L5-L8
this is part of the file structure of the project
src
└── repro
└── demo.cljs
packages
├── A
│ ├── dist
│ │ └── foo.js
│ ├── package-lock.json
│ └── package.json
└── B
├── node_modules
│ └── A -> ../../A
├── package-lock.json
├── package.json
└── src
├── one.js
└── two.js
When I clicked “Stop” in the middle of a compile then clicked “Compile” again, now the exports are being parsed properly
OK it looks like the issue is indeed fixed. watch, compile, and release work on my end now
did you maybe run a compile before the change? the package.json is cached, so maybe it just had the old one
In any case, it works now. A sequence of “stop” and “compile” somehow evicted that cache
Restarted shadow-cljs in REPL, this time making sure to not compile before patching shadow.build.npm
. It indeed works
I’m trying to install Swiper Element … I think I’ve followed the shadow-cljs npm module guide, but something is wrong somewhere.. My ns declaration:
(ns qrart.homepage
(:require [qrart.qr :as qr]
[uix.core :as uix :refer [defui $]]
#?(:cljs [uix.dom])
#?(:cljs ["swiper/element/bundle" :refer [register]])
[shadow.css :refer [css]]))
The error:
The required JS dependency "swiper/element/bundle" is not available, it was required by "qrart/homepage.cljc".
Dependency Trace:
qrart/preload.cljs
qrart/homepage.cljc
Searched for npm packages in:
/Users/danielneal/development/qrart/node_modules
The docs for Swiper say to do this:
// import function to register Swiper custom elements
import { register } from ‘swiper/element/bundle’;
// register Swiper custom elements
register();
`
I’ve done the npm install swiper
step.
Have I mistranslated the import?first check: does /Users/danielneal/development/qrart/node_modules/swiper/package.json
exist?
Yep the node_modules/package.json exists ➕
thheller/shadow-cljs {:mvn/version “2.19.1”} is my shadow-cljs version
that is too old. proper support for exports was added way later and that package uses exports
ah great, I’ll update
Sorry for the noise!
swiper-element-bundle is a .mjs
file - is that a factor?
I find the js modules space tricky to wrap my head around
Hello. I’m new to CLJS and re-frame (but not to Clojure.) My first re-frame-template project was going well, until I quit the shadow-cljs REPL within Emacs.
When I restart it (using M-x cider-jack-in-cljs
), it appears to start up normally within Emacs, but the browser has a red banner that says Stale output! Your loaded JS was not produced by the running shadow-cljs instance. Is the watch for this build running?
and indeed no changes I make in the source files appear in the browser. I’ve tried restarting, emptying cache and hard reloading.
Anyone know what might be going on?
jack-in is an extremely complex setup and I do not know if you have configured that correctly, nor would I know how that looks
I do not know if the watch for this build is running. I did not do that manually the first time, when it worked. That was somehow spawned by cider-jack-in-cljs
. Whatever it did the first time did not happen the second time.
Perhaps someone more familiar with cider-jack-in-cljs
can add some insight.
you can open http://localhost:9630 for the shadow-cljs UI
The docs clearly indicate that cider-jack-in-cljs
is supported and valid: https://shadow-cljs.github.io/docs/UsersGuide.html#cider
That’s OK. Thanks for the info. Perhaps someone else will be more familiar with the jack-in command
It works now.
I deleted the .dir-locals.el
file (which the same above linked docs suggest setting up in section 15.2.2 as a means of storing defaults). I killed the existing session, and restarted with cider-jack-in-cljs
, and it just worked as expected after that.
I have no information beyond that, but I leave this here for future searchers who might encounter this issue.