has anyone succeeded in running a cherry project with go? I’ve tried using goja for this, but it doesn’t support import statements… 🧵
…and I’m no JS expert by any means. tried using esbuild, but it won’t help: with format=esm, I still have import statements; with format=cjs, it gives a warning about import.meta.url and the resulting file fails to work with goja, too.
squint and cherry don't use import.meta.url, perhaps you are using this in your own program?
import and import.meta.url are ES6 constructs. it seems goja doesn't support ES6
> ECMAScript 5.1
yeah I saw that but they also claim to support some ES6 so I thought I’d give it a shot 😄
npx esbuild cherry.mjs --bundle --platform=node --outfile=foo.mjs
▲ [WARNING] "import.meta" is not available with the "cjs" output format and will be empty [empty-import-meta]
cherry.mjs:4:77:
4 │ cherry_core.prn.call(null, fs.existsSync.call(null, fileURLToPath.call(null, import.meta.url)));
╵ ~~~~~~~~~~~
You need to set the output format to "esm" for "import.meta" to work correctly.I don’t have any added code yet, cherry.mjs is the product of cherry run’ing
(ns example
(:require ["fs" :as fs]
["url" :refer [fileURLToPath]]))
(prn (fs/existsSync (fileURLToPath js/import.meta.url)))
(defn foo [{:keys [a b c]}]
(+ a b c))
(js/console.log (foo {:a 1 :b 2 :c 3}))oh wait. there it is 😳
running the script without the import through the esbuild I get another error
panic: ReferenceError: module is not defined at cherry.mjs:24:1(37)
goroutine 1 [running]:
main.main()
/Users/stephan/Sources/srenatus/cherry-go/main.go:14 +0x105
exit status 2
where line 24 is
module.exports = __toCommonJS(cherry_exports);hmm esbuild with --format=iife gives me console is not defined at ...
there’s https://github.com/dop251/goja_nodejs for that
(sorry for thinking out loud)
huh I guess this kinda-sorta worked
srenatus/cherry-go % npx cherry run cherry.cljs
[cherry] Running cherry.cljs
6
srenatus/cherry-go % npx esbuild cherry.mjs --bundle --platform=node --outfile=foo.mjs --format=iife
foo.mjs 473.9kb
⚡ Done in 50ms
srenatus/cherry-go % go run main.go
2025/01/08 10:55:21 6
2025/01/08 10:55:21 val: undefined goja.valueUndefined
srenatus/cherry-go %@stephan.renatus what was your experience with Goja so far, did you get things working to any extent? Found it's available in https://pocketbase.io/docs/js-overview/ and got curious about Cljs support.
esbuild takes a target option, try --target=es5
I haven't done anything beyond the quarter-hour hack above, sorry. no insights.