Fork me on GitHub
#shadow-cljs
<
2024-05-15
>
neumann04:05:29

I'm having an issue with goog.string.format not being defined under an advanced build, but working just fine in a development build. Minimalist example:

(ns app.lib.time
  (:require
    [goog.string :as gstring]))

(defn time-str
  ([]
   (time-str (date-obj)))
  ([^js/Date date-obj]
   (gstring/format "%02d:%02d:%02d" (.getHours date-obj) (.getMinutes date-obj) (.getSeconds date-obj))))
The error is:
app-d806f99da65c17cb4afc3c17a5f19e4952880d09.js:11676 Uncaught TypeError: $goog$string$$.format is not a function
That's with :pretty-print and :pseudo-names enabled. I'm also using deps.edn for my dependencies:
:deps {org.clojure/clojure {:mvn/version "1.11.3"}
        org.clojure/clojurescript {:mvn/version "1.11.132"}

        thheller/shadow-cljs {:mvn/version "2.28.6"}
        com.google.javascript/closure-compiler-unshaded {:mvn/version "v20240317"}
        ...

neumann04:05:03

This is part of a codebase that I'm moving from Figwheel to shadow-cljs.

neumann04:05:52

In the compiled output, it's being turned into:

$goog$string$$.format("%02d:%02d:%02d", ...)

neumann04:05:19

> Sometimes symbols are not auto-included when requiring their parent namespace. This happens when those symbols are in their own file and require specific inclusion

neumann05:05:17

I wonder why I didn't run into this before. Strange.

thheller05:05:06

probably some :preloads depended on it for you, so it was loaded

neumann05:05:55

Oh! I’ll check that. Thanks!

Victor Rosa14:05:36

Hi guys! I have a couple of lambdas in cljs using shadow-cljs on my work, and now they're throwing some kind of error that I never saw, unfortunately, I'm pretty new to this project, so I had no idea what broke the lambdas... It seems it's related to some sort of ws package which is not supposed to be a direct dependency:

errorMessage	
Error: Cannot find module 'ws'
Require stack:
- /var/task/build/handler.js
- /var/runtime/index.mjs
errorType	
Runtime.ImportModuleError
stack.0	
Runtime.ImportModuleError: Error: Cannot find module 'ws'
stack.1	
Require stack:
stack.2	
- /var/task/build/handler.js
stack.3	
- /var/runtime/index.mjs
stack.4	
at _loadUserApp (file:///var/runtime/index.mjs:1087:17)
stack.5	
at Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)
stack.6	
at start (file:///var/runtime/index.mjs:1282:23)
stack.7	
at file:///var/runtime/index.mjs:1288:1
If I ignore that fact and install the ws package directly, I get this:
Have you ever seen that? 
@message	
2024-05-09T18:03:51.931Z	undefined	ERROR	shadow-cljs - remote-error Error: connect ECONNREFUSED 127.0.0.1:9630
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 9630
}
I saw this issue on a package that uses shadow-cljs and wonder if it is related :thinking_face: https://github.com/penpot/penpot/discussions/498

thheller15:05:01

the shadow-cljs devtools use the ws package, so if you intend on using those you need to install it either directly or via the shadow-cljs npm dependency

thheller15:05:13

otherwise you can disable them in your build via :devtools {:enabled false}

thheller15:05:48

the error otherwise just says that the created build output could not connect back to the shadow-cljs server (for REPL and hot-reload)

thheller15:05:16

that could happen for many reasons. can't comment without more details about the setup

Victor Rosa17:05:42

Hmmmm, lemme try this devtools first. It shouldn't be enabled for the lambdas anyway. The setup seems straighforward: deps on shadow-cljs.edn and all the handlers in the main file.

thheller17:05:32

by setup I meant where is the output running, in which runtime. where is shadow-cljs running? as you can see it tries to connect to 127.0.0.1. so if any containers or VMs or whatever are involved that may be the issue

Victor Rosa17:05:02

Nothing like talking to the one who knows stuff hahahaha :devtools {:enabled false} fixed the problem! Thanks ❤️