well I tried to use webpack conditional eliding as a way to solve the cljs-ajax problem of trying to support node and it just didn’t work. I got conditional eliding to work with a constant value, but there was no route to make this work AFAIK. And its kind-of a shame because a macro
could make quick work of this, but we have to introduce something to let the macro know the target env.
OK I found a way to do a conditional node require:
(cond
(exists? goog/global.XMLHttpRequest)
goog/global.XMLHttpRequest
(exists? goog/global.require)
(goog/global.require "xmlhttprequest")
:else nil)
require
is not a global, it is not bound to the global in node.
node wraps every file it loads in
function(module, exports, require) {
// code
}
this is were require
is coming from, it is different for each file. so if you capture it somewhere and bind it to global you are going to inherit the semantics of that initial file.
but there is a global require right
on this
no there is not
node is a runtime
its not compiled
I’m doing this for node
OK i got you but if I inherit the require for the global this
ok
this
is the exports
passed into the function above for node commonjs modules
well I can make this work as well
(let [x require] (x “yada”))
its gotta not be optimized out
yes, you can get creative and hide the require so webpack doesn't see it
by advanced
@thheller thanks!
note that is all really just temporary. libraries are going to have to come up with a different way of doing this.
with ESM conditional requires will no longer be possible and thats definitely the direction everything is going. at least for now.
another reason I'm hesitant to do anything in ClojureScript itself about it - all this stuff seems too transient
not that the solutions they intend for this (eg. import maps) are exactly pretty either ...
webpack5 is also going to be much stricter about all of this. so thats gonna be interesting to watch too.
they've been talking about "breaking changes" for over a year now
oh goody
and the JS eco-system ruptures
well ultimately I think its a good thing they are doing this. they created the problem in the first place and have to fix it some day 🙂
but there are also many other new and interesting webpack alternatives coming up so we'll see what the impact of those are
can I PR this guide to use ["npx" "webpack@4.43.0" ...
?
I think that we can push this "habit" in cljs community of use pinned versions for avoid breaking changes,
https://github.com/clojure/clojurescript-site/blob/master/content/reference/compiler-options.adoc#bundle-cmd
go for it
Not sure where to report ClojureScript bugs? Is it on http://ask.clojure.org like for Clojure ?
Any case, with 1.10.773
I get this error if I am using both :target :bundle
and :install-deps true
:
{:clojure.main/message
"Execution error (IllegalArgumentException) at cljs.closure/compute-upstream-npm-deps$fn (closure.clj:2440).\ncontains? not supported on type: java.lang.Boolean\n",
:clojure.main/triage
{:clojure.error/class java.lang.IllegalArgumentException,
:clojure.error/line 2440,
:clojure.error/cause
"contains? not supported on type: java.lang.Boolean",
:clojure.error/symbol cljs.closure/compute-upstream-npm-deps$fn,
:clojure.error/source "closure.clj",
:clojure.error/phase :execution}
[...]
[cljs.closure$compute_upstream_npm_deps invoke "closure.clj" 2430]
[cljs.closure$maybe_install_node_deps_BANG_
invokeStatic
"closure.clj"
2587]
[cljs.closure$maybe_install_node_deps_BANG_
invoke
"closure.clj"
2585]
> Is it on http://ask.clojure.org like for Clojure ? yes
@didibus that one should have been fixed for Figwheel, report it JIRA provide minimal repro inline in the ticket
@dnolen lots of people don't have jira access, they should report on http://ask.clojure.org
ah k didn't know that was the recommendation now
https://clojure.org/community/contributing#_reporting_problems_and_requesting_enhancements
we have a limited number of jira users on the cloud system (many thanks to Atlassian for providing it for free) so we are limiting jira accounts just to those doing development (ie providing patches) and trying to use http://ask.clojure.org for problem reporting and voting
apologies if I have not properly relayed all this to you in the past
Ok, will do. I'll try and make a minimal repro.
ok I think we may need to update a couple of pointers on the website too
feel free to steal from http://clojure.org :)