This shows how to require ES modules in a node script which is itself compiled as an ES module by shadow. I made this to verify if nbb's way of requiring ES modules aligns with other tools that accomplish the same using the CLJS compiler.
Build with npx shadow-cljs compile script
.
Run with node out/script.js
. It will print something like:
#js {:columns 202, :rows 45}
[Function: Spinner]
The
"ink-spinner$default.default"
can be explained by the package being written in typescript but only published as commonjs.https://unpkg.com/browse/[email protected]/build/index.js
In the early days of commonjs <-> esm interop webpack and others did some "smart" detection as to seemingly make interop easier. See the
__esModule
marker which was used to make commonjs look like ESM as in it allowedimport { thing } from "actually-commonjs"
.node
never did such tricks and only allowsimport thing from "actually-commonjs"
. So only onedefault
import which is the object exported by the package, which again only has thedefault
property.