Felix
06/12/2024, 3:13 PMReferenceError: require is not defined
at <global>.eval (eval at AbortController(file:///mnt/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/js/src/io/ktor/client/engine/js/compatibility/Utils.kt:46:34), <anonymous>:1)
The project is targeting ES modules
useEsModules()
This used to work correctly with 1.9.21
The ktor version is 2.3.11turansky
06/12/2024, 3:34 PMhfhbd
06/12/2024, 3:52 PMEdoardo Luppi
06/12/2024, 6:08 PMturansky
06/12/2024, 6:29 PMLike, we can’t create a proper library ecosystem without it.It’s not true unfortunately
turansky
06/12/2024, 6:30 PMWe REALLY need the separation between browser and NodeProblem is wider and 2 targets won’t solve it
turansky
06/12/2024, 6:31 PMneed the separation between browser and Nodeand worker and service worker and audio service and Deno and Bun and ….
Edoardo Luppi
06/12/2024, 6:50 PMturansky
06/12/2024, 7:11 PMturansky
06/12/2024, 7:13 PMandylamax
06/13/2024, 7:59 AMandylamax
06/13/2024, 8:00 AMFelix
06/17/2024, 9:32 AMturansky
06/17/2024, 9:35 AMturansky
06/17/2024, 9:36 AMDefinePlugin
Without bundler - Gradle task with replace after compileFelix
06/17/2024, 9:49 AMEdoardo Luppi
06/17/2024, 9:50 AMrequire
call is hardcoded, and can't work in ESM mode.Felix
06/17/2024, 10:00 AMhfhbd
06/17/2024, 10:00 AMturansky
06/17/2024, 10:01 AMwhich is not available with 1.9.24Available 🙂
turansky
06/17/2024, 10:02 AMFelix
06/17/2024, 10:04 AMFelix
06/17/2024, 10:06 AMturansky
06/17/2024, 10:07 AMDefinePlugin
can replace require("abort-handler")
with your custom code.
2. If you don't use bundler - you can do the same replace in doLast
of task, which produces *.mjs
fileturansky
06/17/2024, 10:10 AMIt only started failing when moving to Kotlin 2.0.Webpack update can be root cause
Felix
06/17/2024, 10:48 AMFelix
06/17/2024, 11:07 AMrequire
seems to be hardcoded in the ktor source code - https://github.com/ktorio/ktor/blob/main/ktor-client/ktor-client-core/js/src/io/ktor/client/engine/js/compatibility/Utils.kt#L51C34-L51C69Edoardo Luppi
06/17/2024, 11:09 AMEdoardo Luppi
06/17/2024, 11:10 AMEdoardo Luppi
06/17/2024, 11:10 AMEdoardo Luppi
06/17/2024, 11:12 AMeval("require")
thing, which will obviously make them incompatible with ESMEdoardo Luppi
06/17/2024, 11:15 AMFelix
06/17/2024, 11:15 AMrequire
would probably be in scope. If kotlin 2.0 runs the tests without any bundling (namely because node already supports ESM), then the error occurs.Edoardo Luppi
06/17/2024, 11:55 AMEdoardo Luppi
06/17/2024, 12:00 PMEdoardo Luppi
06/17/2024, 12:01 PM