squint 2024-11-16

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

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

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

and require should read as:

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

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

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)

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

relative to root

import path is relative to path

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

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]))

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

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

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

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

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

I did, and restarted repl and watch process

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

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

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

> that works. what exactly works

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

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

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

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

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

alright, allow me some minutes to do this

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

👍 1