I am playing with firebase functions. below is small example of adding doc to firestore, it works in nbb, but i am getting errors with squint run The main goal of my project is to send data from frontend to backend using transit, it works with clojure app engine. And I would like to implement same stuff with nbb and squint. First I would like to have a working code in repl (nbb repl works), and then deploy it to functions emulator, and then into cloud, I don't know how to prepare compiled output that google tools will grab all generated files (I know how Jack Rusher solved it), but in my case i am afraid that loadFile will on every run load deps and compile libs; transit. Which is not good for example how to include generated js into build [squint] Compiling CLJS file: .nbb/.cache/15b1e67a44aa6dd4bb09de2e60634b85262264cb/nbb-deps/cognitect/transit.cljs [squint] Wrote file: ~/pager/functions-cljs/dist/.nbb/.cache/15b1e67a44aa6dd4bb09de2e60634b85262264cb/nbb-deps/cognitect/transit.js But to return to squint run
npx squint run index.cljc
[squint] Running index.cljc
(node:2015510) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
~/pager/functions-cljs/dist/index.js:1
import * as squint_core from 'squint-cljs/core.js';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1274:20)
at Module._compile (node:internal/modules/cjs/loader:1320:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
at Module.load (node:internal/modules/cjs/loader:1197:32)
at Module._load (node:internal/modules/cjs/loader:1013:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:202:29)
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
Node.js v18.19.1
squint.edn
{:paths ["."]
:deps {com.cognitect/transit-cljs {:mvn/version "0.8.280"}}
:extension ".js"
:output-dir "dist"}
nbb.edn
{:deps {com.cognitect/transit-cljs {:mvn/version "0.8.280"}}}
deps in package.json
{
"dependencies": {
"firebase-admin": "^12.1.0",
"firebase-functions": "^5.0.0",
"squint-cljs": "^0.8.113"
}
}
(ns index
(:require ["firebase-functions/v2/https" :refer [onRequest]]
["firebase-admin$default" :as admin]
["firebase-admin/firestore" :refer [getFirestore Timestamp]]
[cognitect.transit :as t]
[nbb.core :as nbb :refer [await]]))
(def project-id "pager")
(comment
(.delete (admin/app))
)
(admin/initializeApp #js {:projectId project-id});
(def emulator? (boolean (.-FIRESTORE_EMULATOR_HOST js/process.env)))
(when emulator?
(println "Emulator"))
(def r (t/reader :json))
(def data "[\"^ \",\"~:emo\",\":warning:\",\"~:thr\",\"7Lxmf6zpg5sEI2dkupGv\",\"~:txt\",\"aaaa\",\"~:uid\",\"NbARSXmCc4N8pOKRSORHUHlPA1VA\",\"~:msg\",null,\"~:lon\",14.5046,\"~:lat\",46.0503,\"~:pic\",null,\"~:to\",\"NbARSXmCc4N8pOKRSORHUHlPA1VA\"]")
(def xdata (.read r data))
(-> (getFirestore)
(.collection "msg")
(.add (clj->js (assoc xdata :ts (Timestamp.now))))
(.then (fn [r] (println "ID:" (.-id r))))) As node says:
: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.You've set extension to "js"
but it has to be either .mjs or you have to set type: module
:deps doesn't work (yet) in squint. use transit as a JS dependency
nbb.core doesn't work in squint either
So transit is compiled because nbb downloaded it. Now I understand.
I understand that nbb.core is just for nbb projects I would solve differences with reader macros.
transit is a built-in dependency of nbb
nbb and squint are so interesting and nbb compiler is so fascinating, i am writing nbb code, but always looking what squint is generating. Because i have original code in js and then nbb in squint const isEmulator = process.env.FUNCTIONS_EMULATOR === 'true'; (def emulator? (boolean (.-FIRESTORE_EMULATOR_HOST js/process.env))) var emulator_QMARK_ = squint_core.boolean$(process.env.FIRESTORE_EMULATOR_HOST); You are really building impressive stack. it looks that you are going to generate, mjs or even wasm files from cljs.
thanks. nbb isn't a compiler but an interpreter. wasm isn't really on my radar.
I just noticed, that empty deps in nbb.edn
{:deps {}}
prevents starting nbb repl in calva, and that bb.edn is required that calva recognizes projectwhat is the problem you're seeing?
I deleted redundant dep transit-cljs from nbb.edn . After a while i restarted a repl, all stopped, jack-in complained that task uberjar is missing. then I was chasing for an hour what went wrong i found out the combination that works.
what bb version do you have
nbb uses bb to download dependencies
v1.3.191
can you start nbb from the command line using e.g. npx nbb ?
I can't reproduce the problems anymore. ➤ nbb Welcome to nbb v1.2.192! user=> ⏎ ➤ npx nbb Welcome to nbb v1.2.192! user=> ⏎