This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-28
Channels
- # aleph (7)
- # babashka (13)
- # beginners (10)
- # biff (4)
- # calva (75)
- # cljs-dev (22)
- # clojure (55)
- # clojure-berlin (1)
- # clojure-europe (15)
- # clojure-nl (1)
- # clojure-norway (35)
- # clojure-serbia (1)
- # clojure-uk (2)
- # clojurescript (46)
- # community-development (1)
- # core-async (23)
- # data-science (1)
- # datalevin (2)
- # datascript (10)
- # datomic (11)
- # fulcro (28)
- # helix (12)
- # hyperfiddle (26)
- # introduce-yourself (4)
- # malli (16)
- # off-topic (1)
- # pathom (4)
- # pedestal (1)
- # polylith (12)
- # quil (11)
- # releases (3)
- # scittle (24)
- # shadow-cljs (85)
- # specter (1)
- # sql (9)
- # xtdb (5)
Hey! I just added [cognitect.transit :as t]
to a :target :esm
+ :js-provider :import
build and it appears to create an invalid import
statement:
1 | import "./cljs_env.js";
^
SyntaxError: Unexpected string literal "./cljs_env.js". import call expects one or two arguments.
hmm in what context does that happen? doesn't look like a shadow-cljs error? and its a perfectly valid import?
It's in bun
โ maybe that is the issue.
Weirdly when I just import the file in a standalone JS file and run it with bun its all fine
Hm now I tried logging whatever cljs_env.js exports and got this error
1 | (function (entry, fetcher)
^
SyntaxError: Missing 'default' export in module 'server-out/cljs-runtime/cljs_env.js'.
no, it's just bun file.js
import env from "./server-out/cljs-runtime/cljs_env.js";
console.log(env)
so exports are only used for release
builds and the defined :modules
in the build config
$ bun js/main.js
Module {
Box: {
$$typeof: Symbol(react.forward_ref),
render: [Function: Box],
displayName: [Getter/Setter],
defaultProps: {
flexWrap: "nowrap",
flexDirection: "row",
flexGrow: 0,
flexShrink: 1,
},
},
Newline: [Function: Newline],
Spacer: [Function: Spacer],
Static: [Function: Static],
Text: [Function: Text],
Transform: [Function: Transform],
measureElement: [Function: measureElement],
render: [Function: render],
useApp: [Function: useApp],
useFocus: [Function: useFocus],
useFocusManager: [Function: useFocusManager],
useInput: [Function: useInput],
useStderr: [Function: useStderr],
useStdin: [Function: useStdin],
useStdout: [Function: useStdout],
}
Can you require transit?
I haven't had an issue until that, it all worked totally fine
[com.cognitect/transit-cljs "0.8.280"]
[cognitect.transit :as t]
Yeah, same here
1 | import "./cljs_env.js";
^
SyntaxError: Unexpected string literal "./cljs_env.js". import call expects one or two arguments.
at <parse> (/mnt/c/Users/thheller/code/shadow-cljs/out/esm-node/js/cljs-runtime/com.cognitect.transit.js:1:1)
I suspect it gets confused by this
if (TRANSIT_NODE_TARGET) {
module.exports = {reader:transit.reader, writer:transit.writer, makeBuilder:transit.makeBuilder, makeWriteHandler:transit.makeWriteHandler, date:types.date, integer:types.intValue, isInteger:types.isInteger, uuid:types.uuid, isUUID:types.isUUID, bigInt:types.bigInteger, isBigInt:types.isBigInteger, bigDec:types.bigDecimalValue, isBigDec:types.isBigDecimal, keyword:types.keyword, isKeyword:types.isKeyword, symbol:types.symbol, isSymbol:types.isSymbol, binary:types.binary, isBinary:types.isBinary,
uri:types.uri, isURI:types.isURI, map:types.map, isMap:types.isMap, set:types.set, isSet:types.isSet, list:types.list, isList:types.isList, quoted:types.quoted, isQuoted:types.isQuoted, tagged:types.taggedValue, isTaggedValue:types.isTaggedValue, link:types.link, isLink:types.isLink, hash:eq.hashCode, hashArrayLike:eq.hashArrayLike, hashMapLike:eq.hashMapLike, equals:eq.equals, extendToEQ:eq.extendToEQ, mapToObject:transit.mapToObject, objectToMap:transit.objectToMap, decoder:decoder.decoder,
UUIDfromString:types.UUIDfromString, randomUUID:util.randomUUID, stringableKeys:writer.stringableKeys, readCache:caching.readCache, writeCache:caching.writeCache};
}
Ahh, just realizing that now, sorry!
I guess it has some detection for module.exports
and doesn't do the partial if (TRANSIT_NODE_TARGET)
evaluation
blame transit since that should never be in that file ... but it has always been in there ...
Trying but getting
--- com/cognitect/transit.js:9
A file cannot be both an ES6 module and a script file that contains at least one goog.provide.
[:server] Compiling ...
[:server] Build failure:
Closure compilation failed with 1 errors
--- com/cognitect/transit.js:9
A file cannot be both an ES6 module and a script file that contains at least one goog.provide.
Sorry, I just made the same mistake again. This appears in the shadow build process
could be a shadow-cljs getting confused since it doesn't have a goog.provide or goog.module call
ah! I think the mere presence of module.exports
makes the closure compiler think this is commonjs
I don't have a simple solution. easiest is probably forking transit and rewriting it a use goog.module
or actual closure-js. dunno why this goog.scope
stuff was used
but also not sure why this works for all the other files but not the transit.js. could totally be shadow-cljs just being confused, but I'm not sure why
Hm bummer... the road to ESM will be bumpy ๐
Hey there! Is there anything I can look at to speed up subsequent shadow-cljs release builds? I can see a significant difference between the calls (140s the first time, 80s after that) but I wonder if thereโs something special to our codebase (too many macros?) that doesnโt allow subsequent calls to be almost a no-op?
$ clj -M:shadow -m shadow.cljs.devtools.cli release app
[:app] Build completed. (4437 files, 4214 compiled, 0 warnings, 143.61s)
$ clj -M:shadow -m shadow.cljs.devtools.cli release app
[:app] Build completed. (4437 files, 25 compiled, 0 warnings, 80.61s)
try with --verbose
to see where actual time is spent. but my guess is that all leftover time is spent in optimizations
otherwise probably worth checking the build report https://shadow-cljs.github.io/docs/UsersGuide.html#build-report
Just checked --verbose, youโre right, Closure - Optimizing ... (75233 ms)
which is 80%. Pretty much no cljs file was compiled except a few with macros inserting contents from non-cljs files. I guess not much we can do to speed up the optimising step?
> Pretty much no cljs file was compiled except a few with macros inserting contents from non-cljs files.
and are those inserted as EDN? deeply nested EDN data optimizes very poorly and slowly
files that remain large after optmization often also mean they took the most time to optimize
unfortunately there are no more detailed stats available, so kinda hard to guess but I helped people before that inlined some rather big EDN data and after my recommendation to remove and fetch at runtime reduced build time by like 90%

not that you should ever even consider inlining anything that large (100kb+) to begin with
> and are those inserted as EDN? deeply nested EDN data optimizes very poorly and slowly Iโll check! Thanks @U05224H0W
Hello, I'm encountering an issue where an external npm package attempts to import lodash.flow
using the import flow from 'lodash/flow'
path syntax (using a slash), which is considered valid according to https://www.labnol.org/code/import-lodash-211117. I'm experiencing the same error when trying to do this from the starter-app. Could it be that this path require method is not supported in Shadow? Everything functions correctly otherwise when I use the lodash.flow
syntax (with a dot). Thank you for your help.
The required JS dependency "lodash/flow" is not available, it was required by "starter/browser.cljs".
Dependency Trace:
starter/browser.cljs
Searched for npm packages in:
c:\clj\shadow-browser-exp\node_modules
which lodash version do you use? its one of those packages that kinda constantly changes how its organized
maybe you just don't have lodash installed at all and only lodash.flow
, which is a separate package
I'm using "lodash.flow": "^3.5.0",
in my test app (original issue was seen in a dep package)
`ls -al node_modules/lodash.flow/ total 34 drwxrwxrwx 1 chaos None 0 2024-03-28 15:53 . drwxrwxrwx 1 chaos None 20480 2024-03-28 15:55 .. -rw-rw-rw- 1 chaos None 1951 2024-03-06 08:24 LICENSE -rw-rw-rw- 1 chaos None 439 2024-03-06 08:24 README.md -rw-rw-rw- 1 chaos None 11640 2024-03-06 08:24 index.js -rw-rw-rw- 1 chaos None 737 2024-03-06 08:24 package.json
`