This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-30
Channels
- # adventofcode (95)
- # announcements (17)
- # babashka (28)
- # beginners (107)
- # calva (34)
- # clj-kondo (7)
- # cljs-dev (20)
- # cljsrn (1)
- # clojure (95)
- # clojure-europe (41)
- # clojure-italy (3)
- # clojure-nl (5)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (77)
- # cursive (7)
- # data-science (1)
- # datalog (4)
- # datomic (12)
- # events (3)
- # fulcro (32)
- # graalvm (2)
- # hugsql (19)
- # introduce-yourself (4)
- # jobs (2)
- # lsp (20)
- # membrane-term (19)
- # numerical-computing (1)
- # off-topic (8)
- # pathom (3)
- # polylith (17)
- # portal (42)
- # re-frame (7)
- # reagent (32)
- # remote-jobs (1)
- # shadow-cljs (86)
- # spacemacs (3)
- # tools-deps (52)
- # uncomplicate (1)
- # xtdb (23)
Is it possible to import local .mjs
files when using shadow-cljs to make a node script? i.e. ECMAScript modules
something like this https://github.com/clojure/clojurescript/commit/233b42338c182e72391466eba2d00bae34271e58
i want to have .mjs
files in my projects source, so dynamically at runtime
but if that’s not possible i’m guessing there’s probably a way to compile them to regular js
files and consume those from shadow
however the files will be part of :advanced
optimizations so you might have to deal with externs
to be clear I'm asking this because node is capable of loading .mjs
files dynamically at runtime without shadow-cljs ever knowing about it (ie. (js/import "./that-file.mjs")
ah got it, thanks!
> I was thrown off by this bit in the docsFor string requires the extension `.js` will be added automatically but you can specify the extension if you prefer. Note that currently only `.js` is supported though.
I thought that meant (:require ["/some/place/file.mjs" :as x])
won’t work
good to know i can use js/import
as a fail safe
doesn’t seem to work, js/import
or shadow.esm/dynamic-import
(js/import "...")
=> ReferenceError: import$ is not defined
(shadow.esm/dynamic-import "...")
=> ReferenceError: shadow_esm_import is not defined
I was able to get it working by defining the dynamic require inside a .js
file
module.exports = import('./index.mjs');
then using js/require
to require this .js
fileis that target undocumented?
this dynamic import work in dev mode but breaks in production silently, looks like it’s failing to load
I'm almost positive that the dynamic import path is not something you should or want to be doing
i agree, i don’t want to use dynamic import
so i’ve got a node script, using the :node-script
target and it’s working well, but I need to add some .mjs
source to the project
but it’s an .mjs
file, will that work?
it’s also a sub module with it’s own package.json
yeah sorry
correct
oh so using yarn i can just add it to the root package json? like so?
"mutesync_engine_win32": "file:./mutesync_engine_win32",
i tried that and get this error
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\19518\src\mutesync\shells\electron\node_modules\mutesync_engine\index.mjs
at Module.load (internal/modules/cjs/loader.js:933:11)
at Module._load (internal/modules/cjs/loader.js:776:14)
at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
at Module.require (internal/modules/cjs/loader.js:959:19)
at require (internal/modules/cjs/helpers.js:88:18)
at C:\Users\19518\src\mutesync\.shadow-cljs\builds\electron-main-dev\dev\out\cljs-runtime\shadow.js.shim.module$mutesync_engine.js:3:41
at global.SHADOW_IMPORT (C:\Users\19518\src\mutesync\shells\electron\js\background\main.js:64:44)
at C:\Users\19518\src\mutesync\shells\electron\js\background\main.js:1757:1
at Object.<anonymous> (C:\Users\19518\src\mutesync\shells\electron\js\background\main.js:1786:3)
at Module._compile (internal/modules/cjs/loader.js:1078:30)
that is the right file though
index.mjs is an ES module
electron is running node so yeah
i can do that for a node script?
are there any known incompatibilities?
lol so what are the options if i want to keep the node-script target?
correct
but a temporary hack would work for now, anything frowned upon i can do with global variables and js*
?
yeah my release build is broken
you can indeed work arround the CLJS compiler renaming to import$
thing but that still doesn't fix release
is there a way to include some extra JS source at the end after the cljs/closure compiler is done doing it’s thing?
or prefix source i suppose would be better
shadow-cljs is not including ANY node_modules
packages in a :node-script
build at all
right
you can make it part of the build, but for that the file needs to be on your classpath and not in node_modules
how’s that?
as I linked yesterday https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js
ah right, so will the closure compiler touch those files?