cljs-dev

dominicm 2023-09-20T19:01:47.809009Z

https://github.com/clojure/clojurescript/blob/0da9884836e9f8ba190f3b789adcb6b9b85a669c/src/main/clojure/cljs/foreign/node.clj#L64 I've just bumped into this line, as that's how mantine now does its exports https://github.com/mantinedev/mantine/blob/350051a3c40e51197bda27d818db013f9bdb90eb/src/mantine-core/package.json#L8-L12 Is there something else I can do instead? I'm using :target :bundle.

dnolen 2023-09-25T17:29:48.957319Z

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

dnolen 2023-09-25T17:29:57.573199Z

Or we mishandle?

dominicm 2023-09-25T18:05:09.999669Z

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

dnolen 2023-09-25T21:31:39.526909Z

that I do not follow?

dnolen 2023-09-25T21:31:52.910369Z

exports is supposed to be for exporting the entry point

dominicm 2023-09-26T02:44:51.446129Z

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

🤯 1
dnolen 2023-09-27T13:44:07.938519Z

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

dnolen 2023-09-27T13:44:31.348009Z

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

dominicm 2023-09-27T13:44:43.071939Z

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

dnolen 2023-09-27T13:50:37.600259Z

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

dominicm 2023-09-27T13:51:27.760879Z

Yeah. There's a to-do to handle ".", but it's not implemented šŸ˜…

dnolen 2023-09-27T13:51:58.180249Z

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

ā¤ļø 1
dominicm 2023-09-27T13:53:07.448299Z

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

dnolen 2023-09-27T13:54:45.061529Z

what else is needed?

dominicm 2023-09-27T13:56:01.493009Z

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&cid=C07UQ678E

dnolen 2023-09-27T13:56:48.456719Z

hrm I don’t know what ā€œfirst fileā€ cannot be handled means?

dnolen 2023-09-27T13:57:11.088659Z

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

dominicm 2023-09-27T13:58:04.616329Z

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.

dnolen 2023-09-27T13:58:22.018579Z

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

dominicm 2023-09-27T14:00:05.655999Z

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

dnolen 2023-09-27T14:00:50.484509Z

k got it - two distinct issues - both seem simple

šŸŽŠ 1
dnolen 2023-09-27T22:49:13.664079Z

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

dominicm 2023-09-28T05:02:02.926969Z

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

dnolen 2023-09-23T19:36:12.714769Z

So is this resolved?

dominicm 2023-09-23T23:41:37.409459Z

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

dominicm 2023-09-23T23:42:59.419849Z

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

dnolen 2023-09-24T00:14:05.647509Z

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

šŸ‘ 1
2023-09-24T01:17:54.489649Z

I think the initial issue was that this didn’t match the indexing? https://github.com/mantinedev/mantine/blob/350051a3c40e51197bda27d818db013f9bdb90eb/src/mantine-core/package.json#L8-L12

dnolen 2023-09-28T16:20:47.813289Z

awsome thanks

dominicm 2023-09-20T19:21:18.245979Z

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

dominicm 2023-09-20T19:21:56.031179Z

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

dominicm 2023-09-20T19:58:39.424459Z

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?

2023-09-20T21:35:20.491629Z

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.

2023-09-20T21:35:52.306419Z

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

dominicm 2023-09-20T21:57:23.402139Z

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 šŸ™„

2023-09-20T22:37:08.674639Z

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