squint

Jeremy 2024-11-16T12:41:38.383019Z

It's my first time using squint or cljs, and I want to integrate it into an existing node project. My cljs files are in server/clj/... , and are compiled to server/... I have 2 files: server/clj/utilities/validators.cljs -> (ns server.utilities.validators) server/clj/services/account_service.cljs -> (ns server.services.account-service) how can i import the 2nd ns from the first? this does't work:

(ns server.services.account-service
  (:require [server.utilities.validators :as vld])) 
Thank you

borkdude 2024-11-16T12:46:34.549069Z

the namespace structure should always follow the directory structure in clojure, also in squint

borkdude 2024-11-16T12:47:07.963469Z

so if you have a squint.edn with {:paths ["server/clj"]} then the namespace should read (ns utilities.validators)

borkdude 2024-11-16T12:49:16.723979Z

and require should read as:

(:require [utilities.validators :as vld])

borkdude 2024-11-16T12:51:47.805069Z

here is an example project: https://github.com/squint-cljs/squint/tree/main/examples/vite-react

borkdude 2024-11-16T12:52:21.360879Z

but I realize the example project doesn't have a directory nesting so I can see how that's confusing for a newcomer to clojure

borkdude 2024-11-16T12:54:13.977669Z

anyway, the way you should organize your project is mention the source directories in squint.edn under :paths and those directories are not part of the namespace name, so if you have {:paths ["src"]}} and src/foo/bar/baz.clj then the namespace name should be (ns foo.bar.baz)

Jeremy 2024-11-16T13:01:54.750249Z

Thanks a lot. I was confused if import path is relative to root, :path, or :output-dir.

borkdude 2024-11-16T13:02:04.350149Z

relative to root

borkdude 2024-11-16T13:02:19.026449Z

no sorry

borkdude 2024-11-16T13:02:23.208689Z

import path is relative to path

borkdude 2024-11-16T13:02:51.749559Z

so if you have a file src/foo/bar/baz.clj you should import it using (:require [foo.bar.baz])

Jeremy 2024-11-16T13:05:40.249399Z

got it. I'm not sure why the require still isn't working tho. I looked at the vite-react example, and I'm also now running a squint watch process in addition to the repl, yet it doesn't work.

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'utilities.validators' imported from c:\home\src\<<my-project>>\node_modules\squint-cljs\lib\cli.js
<<project-root>>/squint.edn
{:paths ["./server/clj/"]
 :output-dir "./server/"
 :extension ".mjs"
 ;; :copy-resources [".csv" ".xlsx"]
 }
<<project-root>>/server/clj/utilities/validators.cljs
(ns utilities.validators)
<<project-root>>/server/clj/services/account_service.cljs
(ns services.account-service
  (:require [utilities.validators :as vld]))

borkdude 2024-11-16T13:13:00.413249Z

{:paths ["server/clj"]
 :output-dir "server"
 :extension ".mjs"
 ;; :copy-resources [".csv" ".xlsx"]
 }
can you try this instead

borkdude 2024-11-16T13:13:33.293559Z

when you you get the error, when running the project ?

borkdude 2024-11-16T13:13:55.088239Z

the node REPL stuff is not finished, require isn't properly working in there yet

borkdude 2024-11-16T13:14:59.459449Z

there's an open issue for that: https://github.com/squint-cljs/squint/issues/369

👍 1
Jeremy 2024-11-16T13:22:51.937429Z

I see. when using the account-service output from node, I get this error:

accountService = await import("./services/account_service.mjs");
file:///c:/home/src/ICAD-Solution/server/services/account_service.mjs:2
import * as vld from './..\utilities\validators.mjs';
                          ^^^^^^
Uncaught SyntaxError: Invalid Unicode escape sequence
so I guess it's a windows path issue

borkdude 2024-11-16T13:25:06.127679Z

if it's a Windows issue, I'll try to debug on my Windows machine later

Jeremy 2024-11-16T13:25:41.136499Z

I did, and restarted repl and watch process

borkdude 2024-11-16T13:26:04.102639Z

to work around this you could also try this (for now):

(:require ["./foo/bar.mjs"])
this should be relative to the file in the output directory let's ignore the REPL part for now, just use the watch process

❤️ 1
borkdude 2024-11-16T13:28:31.918639Z

I'll try the vite react project on Windows... brb

Jeremy 2024-11-16T13:30:05.937059Z

that works. looks like the issue before was this output line: import * as vld from './..\utilities\validators.mjs'; mixing unix with windows style path

Jeremy 2024-11-16T13:30:42.096019Z

thanks a lot @borkdude

borkdude 2024-11-16T13:31:22.218059Z

> that works. what exactly works

Jeremy 2024-11-16T13:33:39.402769Z

this:

(ns services.account-service
  (:require ["../utilities/validators.mjs" :as vld]))
also, correcting: import * as vld from './..\utilities\validators.mjs'; to import * as vld from './../utilities/validators.mjs'; in the acccount_services.mjs file

Jeremy 2024-11-16T13:33:39.812689Z

>> to work around this you could also try this (for now): >

(:require ["./foo/bar.mjs"])

borkdude 2024-11-16T13:34:21.297769Z

ah ok

borkdude 2024-11-16T13:44:19.624029Z

the vite react project works fine over here in Windows. could it be that the REPL output interfered with the normal squint output?

borkdude 2024-11-16T13:45:20.438719Z

if possible, make a repro project on Github that I can run in Windows, then I can have another look at the problem

Jeremy 2024-11-16T13:48:45.973049Z

alright, allow me some minutes to do this

borkdude 2024-11-16T13:49:33.191069Z

yeah sure, no hurry. I need to go away in a bit, so I won't look at this today probably

👍 1
Jeremy 2024-11-16T14:06:16.273459Z

https://github.com/jeremy302/squint-ns

🎉 1