This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-20
Channels
- # announcements (10)
- # babashka (12)
- # beginners (30)
- # calva (15)
- # clerk (7)
- # clj-kondo (15)
- # clojure (22)
- # clojure-art (2)
- # clojure-austin (1)
- # clojure-berlin (1)
- # clojure-europe (22)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-uk (5)
- # cursive (3)
- # hoplon (1)
- # hyperfiddle (26)
- # introduce-yourself (1)
- # jobs (1)
- # joyride (13)
- # kaocha (6)
- # lsp (5)
- # matrix (1)
- # music (1)
- # off-topic (8)
- # podcasts-discuss (1)
- # practicalli (1)
- # releases (1)
- # sci (43)
- # shadow-cljs (67)
- # squint (56)
- # tools-deps (3)
I'm writing some tests in cljs code and encountering the following error when importing an esm module. I tried several different import styles. Is there a way around this?
[:test] Compiling ...
========= Running Tests =======================
SHADOW import error /home/chrism/dev/cljs-dopeloop/.shadow-cljs/builds/test/dev/out/cljs-runtime/shadow.js.shim.module$audio_buffer.js
/home/chrism/dev/cljs-dopeloop/tests.js:64
/* ignore this, look at stacktrace */ fn.call(global, require, module, __filename, __dirname);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/chrism/dev/cljs-dopeloop/node_modules/.pnpm/[email protected]/node_modules/audio-buffer/index.js from /home/chrism/dev/cljs-dopeloop/tests.js not supported.
Instead change the require of index.js in /home/chrism/dev/cljs-dopeloop/tests.js to a dynamic import() which is available in all CommonJS modules.
at /home/chrism/dev/cljs-dopeloop/.shadow-cljs/builds/test/dev/out/cljs-runtime/shadow.js.shim.module$audio_buffer.js:3:81
at global.SHADOW_IMPORT (/home/chrism/dev/cljs-dopeloop/tests.js:64:44)
at /home/chrism/dev/cljs-dopeloop/tests.js:1416:1
at Object.<anonymous> (/home/chrism/dev/cljs-dopeloop/tests.js:1428:3)
shadow-cljs.edn
{:source-paths ["src"]
:dependencies []
:builds {:test {:target :node-test
:output-to "tests.js"
:ns-regexp "dopeloop.*$"
:autorun true
:compiler-options {:output-feature-set :es8}
}}}
require: ["audio-buffer$default" :as AudioBuffer]
that is node telling you that it cannot require esm modules. there is no way arround that, as it is a node limitation
Ah ok, but I guess there's no way to get :node-test
to also be esm?
not currently no, I have some plans that might enable this but thats gonna take a while
Ok no worries. I'll try to figure something else out for now, thank you.
Hey, I’m trying to write some script that needs to run in browser, is there any target I can use? (headless chrome or something?)
do you mean a script to run a browser? like puppeteer? https://pptr.dev/
I’m running a script that some of its deps require a browser (the error i’m getting in node is google not found)
what does "google not found" mean? I mean what does that mean even in a browser context? 😛
I mean if you want something to control a browser you can use the above puppeteer with :node-script
for example, but have all your other stuff in a regular :target :browser
build
its really hard to give you any answers without knowing what the actual problem is that you are trying to solve
i’ll try to explain the specific issue: • I have a build for browser • I’m writing a script that uses this build • The script read some var from the browser build, which uses google maps lib for some def This means the script need a browser environment
it’s an internal lib (cljs, for browser), the lib exporting a map that the script requires
is there something built in for shadow (like karma?) if not, what should i do? build for a browser and run using puppeteer?
I'm still not quite sure what problem you are trying to solve, so my guesses might not fit
but yes, two builds one for the browser, one :node-script
using something like puppeteer to open a headless browser and interact with it
i’m not sure about something, let’s say i’m running puppeteer from the node-script, how do i run the build for the browser in it?
Hello. Anyone using https://github.com/henryw374/cljc.java-time with shadow-cljs? We have been using it with cljsjs with no problem, but with shadow we are having some trouble. Using most of the functions works, but when dealing with timezone related one we get "zone.rules is not a function]" error. I suspect it's because for some reason js-joda/timezone is not being loaded. Any idea what could be? In package.json we have the following:
"@js-joda/core": "5.6.1",
"@js-joda/timezone": "2.18.2",
And in the code we require `js-joda/timezone like this:
["@js-joda/timezone"]
I encountered something similar when experimenting with updating my dependencies. This was with tick. From reading other threads by Henry here on Clojurians slack, it appears we need to be using using the same versions of js-joda as you find in the deps used for tick. See https://github.com/juxt/tick/blob/master/src/deps.cljs and https://github.com/henryw374/cljs.java-time/blob/master/src/deps.cljs
{:npm-deps {"@js-joda/timezone" "2.5.0"
"@js-joda/locale_en-us" "3.1.1"}}
{:npm-deps {"@js-joda/core" "3.2.0"}
:externs ["cljsjs/js-joda/common/js-joda-dup.ext.js"]}
I have been using newer versions of js-joda, but just noticed I'm still using locale ~3, when trying 4.x shadow-cljs fails to load the file. I made a small reproduction with a comparison of a working vite version: https://github.com/dvingo/shadow-cljs-js-joda-locale-bug
sorry not a clue. can't say what is going on. everything looks ok to me on the compiler side
might be the closure compiler rewriting the code in some way that doesn't work, but its gonna be hard to reproduce this with just the closure compiler
Thank you all for your responses.
I tested with the versions pointed by wevrem, and I was getting the same errors. But then I realized I was just using the library wrong. I did a mistake when copy/pasting from another project where it works, so I didn't even consider the code might be wrong 😅
After fixing the code the library works even with the latest available versions.
But I'm not using js-joda/locale-en-us
, just core
and timezone
. Nevertheless I can confirm that using the latest locale-en-us
version throws the error pointed by dvingo.
thanks for taking a look @U05224H0W in a case like this would the only option be to add it as global and use js-options to refer to it?
well you can always use any other bundler for the JS parts https://shadow-cljs.github.io/docs/UsersGuide.html#js-provider-external
oh man, totally missed that - I was trying to bundle it using webpack and then require it (https://shadow-cljs.github.io/docs/UsersGuide.html#_requiring_js) but that still had the error - the external provider should work for me, thank you!
if anyone is interested in using the latest js-joda locale package I updated that repo with an example of bundling it using rollup https://github.com/dvingo/shadow-cljs-js-joda-locale-bug (check the last commit to see the changes) I still wanted shadow-cljs to handle the rest of my npm deps, so this is a nice workaround
this is absolutely NOT recommended. the issue is that any common dependency that the "externalized" dependencies might have, will now be duplicated and maybe incompatible with each other
don't know what the dependency situation in this case looks like, but say js-joda dependent on something you also still leave shadow-cljs to bundle. then you'd 2 have versions of the "same" thing
ah good to know, so the external bundle would be the way to go then - I was wondering if you have multiple shadow-cljs modules if you can get an external file for each bundle with the js deps used for that bundle? this way you can package the js deps for each cljs bundle to split things up at a more granular level
So you would have one common externals.js file, then one per bundle that has the unique js dependencies per each bundle
I am trying to load specific files from a large JS library (https://mantine.dev/getting-started/) using the techniques described here: https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages but shadow is failing to resolve the file:
package @mantine/core had exports, but could not resolve ./cjs/core/MantineProvider/MantineProvider
{:package #object[java.io.File 0x89fce71 "/home/user/shadow-cljs-mantine/node_modules/@mantine/core"], :require-from nil, :rel-require "./cjs/core/MantineProvider/MantineProvider"}
ExceptionInfo: package @mantine/core had exports, but could not resolve ./cjs/core/MantineProvider/MantineProvider
the package includes both esm and commonjs and I get the same error when trying either. I put together a repo here https://github.com/dvingo/mantine-shadow-cljs-import-one demonstrating this
Any ideas on how to resolve this?"exports"
defined in this package.json https://unpkg.com/@mantine/[email protected]/package.json
define which files you are allowed to access directly. so in this case you are not supposed to access this file directly