Fork me on GitHub
#cljs-dev
<
2023-09-20
>
dominicm19:09:18

It does seem to be indexed as @mantine/core, so I'm a bit confused about why I'm getting an error, actually. user=> (filter #(contains? (set (:provides %)) "@mantine/core") (cljs.closure/index-node-modules-dir nil)) ({:file "/home/overfl0w/workshop/app2/node_modules/@mantine/core/esm/index.js", :module-type :es6, :provides ["@mantine/core/esm/index.js" "@mantine/core/esm/index" "@mantine/core" "@mantine/core/esm"]})

dominicm19:09:56

I get

No such namespace: @mantine/core, could not locate _CIRCA_mantine_SLASH_core.cljs, _CIRCA_mantine_SLASH_core.cljc, or JavaScript source providing "@mantine/core" (Please check that namespaces with dashes use underscores in the ClojureScript file name) in file src/.../foo.cljs

dominicm19:09:39

OK, so switching to :package-json-resolution :webpack solves my problem with mantine... but introduces a problem with another library which has "module": "dist/index.esm.mjs" . That isn't detected by https://github.com/clojure/clojurescript/blob/0da9884836e9f8ba190f3b789adcb6b9b85a669c/src/main/clojure/cljs/foreign/node.clj#L125-L128 so ends up getting ignored, rather than trying the next entry. patch welcome?

mikerod21:09:20

It’s not a perfect solution but if cljs doesn’t export indexing the way you need, you could figure out what CLJS does find and use that in your :require If you are using newer bundler like webpack v5+, it’ll fail due to it violating the package exports. You can workaround that with an explicit resolve.alias entry in the config.

mikerod21:09:52

So you’ll end up with a package structure dependent :require to get CLJS to recognize it.

dominicm21:09:23

I was violating the webpack package exports... but I didn't know about the resolve.alias, that's handy! I ended up setting a custom :package-json-resolution ["browser" "main" "module"] which happens to work for my dependencies :face_with_rolling_eyes:

mikerod22:09:08

I’ve never messed with the new resolution options there. But good! I’ve used resolve.alias quite a bit for webpack. But it’s nice if you don’t need to

dnolen19:09:12

So is this resolved?

dominicm23:09:37

Not exactly, no. I have a workaround, but it only happens to work because I'm not using many npm dependencies right now.

dominicm23:09:59

It's definitely plausible my workaround will bite me later. It's also quite unfriendly to figure out right now.

dnolen00:09:05

I'm not against adding another thing to match if that isn't going to cause problems

👍 1
dnolen17:09:48

But what is the problem? Is the exports actually wrong?

dnolen17:09:57

Or we mishandle?

dominicm18:09:09

Npm exports won't contain the npm dependency. So mishandle.

dnolen21:09:39

that I do not follow?

dnolen21:09:52

exports is supposed to be for exporting the entry point

dominicm02:09:51

It does, but providing a map seems to let them distinguish between es6 import and cjs require.

🤯 1
dnolen13:09:07

but what is the actual problem I guess? that we should have a knob to choose one or the other?

dnolen13:09:31

I improved the exports handling to at least make it easier to fix up stuff like this and easily add test cases

dominicm13:09:43

No knob needed I think. Just need to recurse in and pick one using the existing strategy.

dnolen13:09:37

oh I see the problem is we just assume there’s one entrypoint

dominicm13:09:27

Yeah. There's a to-do to handle ".", but it's not implemented 😅

dnolen13:09:58

ok I will take a look this week, this seems easy

❤️ 1
dominicm13:09:07

Yeah I think it is. There's a couple of bits of low hanging fruit here.

dnolen13:09:45

what else is needed?

dominicm13:09:01

The main need is handling ".". But it would also be easy to add support here for falling back if the first file can't be handled. https://clojurians.slack.com/archives/C07UQ678E/p1695239919424459?thread_ts=1695236507.809009&amp;cid=C07UQ678E

dnolen13:09:48

hrm I don’t know what “first file” cannot be handled means?

dnolen13:09:11

in what situations could that occur? Sorry this stuff is not that easy to understand w/o being crystal clear

dominicm13:09:04

Can't be handled in this case means that the file extension was .mjs, and the package resolution code I linked can't handle that. In that case it would be useful to try the next thing in the list and see if that can be handled.

dnolen13:09:22

basically I don’t want to collapse two issues into one, otherwise I’m going to get confused what we’re talking about here.

dominicm14:09:05

Yeah, that's fair. Handling . Is the main thing

dnolen14:09:50

k got it - two distinct issues - both seem simple

🎊 1
dnolen22:09:13

what is this esm.js case? like what is the dependency, the unit tests install them to do the check.

dominicm05:09:02

@mantine/mantine-core for the first case, and react-hook-form-mantine for the second.