Hi. I'm facing a "ReferenceError: require is not d...
# ktor
f
Hi. I'm facing a "ReferenceError: require is not defined" error on
Copy code
ReferenceError: 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)
	at <global>.AbortController(file:///mnt/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/js/src/io/ktor/client/engine/js/compatibility/Utils.kt:46)
	at <global>.commonFetch(file:///mnt/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/js/src/io/ktor/client/engine/js/compatibility/Utils.kt:19)
when running tests on the js/node target, after moving from kotlin 1.9.21 to 2.0.0. • The error does not occur when running on the js/browser target. • The error didn't exist on kotlin 1.9.21 • I'm targeting ES modules (
useEsModules()
)
e
@stanislav.erokhin, could you check?
f
This seems to be caused by the following line - https://github.com/ktorio/ktor/blob/main/ktor-client/ktor-client-core/js/src/io/ktor/client/engine/js/compatibility/Utils.kt#L51C34-L51C69 When packaging the app using ESM modules, the
require
function is not available in the module scope.