Hello there!
I have to admit that I fail at requiring a ESM module in our node js app - The goal is to render parts of our apps on the server side. We have three builds:
-
dev
using:target :node-script
- This is the only target I tested so far, but the solution should work for all three -
app
using:target :node-library
- Will be deployed to a lambda function -
test
using:target :node-test
And the usage looks a bit like this:
(ns my-app
(:require
[react-markdown]
[remark-breaks :default remark-breaks]
[remark-directive]
[remark-heading-id]
[remark-unwrap-images]
(defn handler []
[:> react-markdown {:remark-plugins [remark-breaks
remark-unwrap-images
remark-heading-id
remark-directive]
:components [...]
:children [...]}]
And I’m getting this error
SHADOW import error /.../proj/target/cljs-runtime/shadow.js.shim.module$remark_breaks.js
.../proj/target/dev.js:64
/* ignore this, look at stacktrace */ fn.call(global, require, module, __filename, __dirname);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /.../proj/node_modules/remark-breaks/index.js from /.../proj/target/dev.js not supported.
Instead change the require of index.js in /.../projr/target/dev.js to a dynamic import() which is available in all CommonJS modules.
I’m confused whether I need to change the targets or somehow adjust the require statement.
Any help would be welcome.
Johannes