Don Kittle
12/03/2023, 7:29 PMCMD "node", "dmseer.js"
to run my app, I get the following error related to a markdown library for React:
dmseer-web-1 | Error [ERR_REQUIRE_ESM]: require() of ES Module /code/node_modules/react-markdown/index.js from /code/dmseer.js not supported.
dmseer-web-1 | Instead change the require of index.js in /code/dmseer.js to a dynamic import() which is available in all CommonJS modules.
dmseer-web-1 | at /code/dmseer.js:5:177
dmseer-web-1 | at Object.<anonymous> (/code/dmseer.js:81:2) {
dmseer-web-1 | code: 'ERR_REQUIRE_ESM'
dmseer-web-1 | }
The code defining my component looks like this:
@file:JsModule("react-markdown")
@file:JsNonModule
package components
import react.FC
import react.Props
@JsName("default")
external val ReactMarkdown: FC<MarkdownProps>
external interface MarkdownProps : Props {
var children: String
}
I build the JS code with jsBrowserProductionRun
(which I think might be my issue), move the package.json to the build folder, run node i
and then make that folder available to the container.
Anyone have any ideas what might be going on? This all works fine when run locally.turansky
12/03/2023, 10:02 PMDon Kittle
12/04/2023, 7:34 AMcommonWebpackConfig {
cssSupport {
enabled.set(true)
}
}
webpackTask {
output.libraryTarget = "commonjs2"
}
turansky
12/04/2023, 7:38 AMandylamax
12/04/2023, 7:46 AMjsNodeProductionRun
instead of jsBrowserProductionRun
Don Kittle
12/04/2023, 8:09 AM> Task :jsNodeProductionRun FAILED
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/don/code/don/dmseer/build/js/node_modules/react-markdown/index.js
require() of ES modules is not supported.
require() of /Users/don/code/don/dmseer/build/js/node_modules/react-markdown/index.js from /Users/don/code/don/dmseer/build/js/packages/dmseer/kotlin/dmseer.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/don/code/don/dmseer/build/js/node_modules/react-markdown/package.json.
turansky
12/04/2023, 8:20 AMturansky
12/04/2023, 8:20 AMpackage.json
Don Kittle
12/04/2023, 2:03 PMreact-markdown
moving to ES modules and not supporting commonjs any more. I downgraded to an older version and resolved that build issue.turansky
12/04/2023, 8:24 PMes
module kind.
You can use it for new versionsDon Kittle
12/04/2023, 8:24 PMDon Kittle
12/04/2023, 8:26 PMjsNodeProductionRun
, though. When I try to run the code this way, I get back the following error:
> Task :jsNodeProductionRun FAILED
ReferenceError: document is not defined
at main (/Users/don/code/don/dmseer/build/compileSync/js/main/developmentExecutable/kotlin/commonMainSources/libraries/stdlib/src/kotlin/util/Standard.kt:63:53)
Don Kittle
12/04/2023, 8:27 PMDon Kittle
12/04/2023, 8:28 PMturansky
12/06/2023, 7:32 AMturansky
12/06/2023, 7:33 AM