This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-01
Channels
- # announcements (10)
- # asami (2)
- # babashka (10)
- # beginners (55)
- # biff (37)
- # calva (9)
- # cherry (1)
- # clj-kondo (11)
- # clojure (221)
- # clojure-bay-area (12)
- # clojure-europe (77)
- # clojure-hungary (3)
- # clojure-nl (5)
- # clojure-norway (12)
- # clojurescript (11)
- # cursive (1)
- # data-science (11)
- # emacs (27)
- # figwheel (3)
- # fulcro (11)
- # graphql (5)
- # helix (7)
- # honeysql (3)
- # humbleui (9)
- # interceptors (2)
- # introduce-yourself (2)
- # kaocha (12)
- # lsp (27)
- # malli (6)
- # nbb (70)
- # off-topic (6)
- # re-frame (6)
- # react (3)
- # reitit (9)
- # releases (2)
- # scittle (29)
- # shadow-cljs (26)
- # sql (13)
- # tools-deps (61)
I am trying to require jquery from scittle and getting Could not find namespace
error:
cljs
(ns jquery-test
(:require
["jquery" :as jq]))
(js/console.log "cljs code ran")
html
<script src=""></script>
<script src=""></script>
<script src="/assets/cljs/jquery_test.cljs" type="application/x-scittle"></script>
Any thoughts why this may not be working?@chromalchemy I think jquery works by defining a global $
or so object which you can use without :require
, just as js/$
If I remove require
and try (js/$.Alert "Hello")
I get this error
for reference, I was able to use
(:require ["jquery" :as jq]))
On a shadow-cljs build and use like
(-> (jq ".options-form") (.serialize))
I don't see .Alert
being defined in the $
object here:
https://codepen.io/jbalsamo/pen/OVdOPV
I see:
ƒ (a,b){return new n.fn.init(a,b)}
iframeConsoleRunner-6bce046e7128ddf9391ccf7acbecbf7ce0cbd7b6defbeb2e217a867f51485d25.js:1 undefined
Ok, thanks. I will find a better function to test. I was going off this https://www.sitepoint.com/ways-jquery-alert/ ps. I understand it’s not shadow, just providing my baseline experience to try to better understand the differences in requiring dependencies.
oh thats from 2011 😵
that linked article
You probably won't need jquery in 2022 anyway, there is a lot of stuff in the browser now
Thanks. I have a call to a (malformed?) endpoint that seems to return html response (instead of json). And jquery.ajax
somehow successfully interprets as jsonp
. I tried fetch
and couldn’t get it to work, even with help from the cljs channel..
Well, if you include jquery in a script tag, you have the js/$
available in scittle scripts, that's how it currently works.
Ok, it is indeed working like that. ex:
(-> (js/$ ".target-elem") (.addClass "text-red-500"))
Works! 🎉
Can scittle cljs require and use code from a pre-existing bundle.js?
Currently this doesn't matter, but in the future scittle may be able to :require
es6 modules directly
Currently it only works if a foo.js file included in a script tag defines some global or you can import it as a module and then manually define some globals
Like here: https://twitter.com/borkdude/status/1528110797884473345 I have this in a branch
Thanks, I will look at that> Not sure the format. It is an older codebase using Webpack / Babel. Here is the webpack config.
var webpack = require('webpack');
module.exports = {
devtool: 'source-map',
bail: true,
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
include: /(assets\/js|assets\\js|node_modules\/@bigcommerce\/stencil-utils|node_modules\\@bigcommerce\\stencil-utils)/,
query: {
compact: false,
cacheDirectory: true,
presets: ['es2015-loose'],
}
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
})
],
watch: false
};
you may be able to deal with that with requirejs
in the browser, then pull out the module, define it as a global and then you can access it from scittle
will try out some of those options. Thx for info