Ktor Version and Engine Used (client or server and name)
io.ktor:ktor-client-js 1.3.0-beta-1 and 1.2.5
Describe the bug
Webpack "Module not found" errors are thrown.
Logs:
WARNING in .._imported/ktor-ktor-client-core/1.3.0-beta-1/ktor-ktor-client-core.js 12165:13-32
Critical dependency: the request of a dependency is an expression
@ ./kotlin/gaia.js
@ multi ./kotlin/gaia.js source-map-support/browser-source-map-support.js
WARNING in .._imported/ktor-ktor-client-core/1.3.0-beta-1/ktor-ktor-client-core.js
Module not found: Error: Can't resolve 'ws' in 'C:\Users\Daan\code\gaia\build\js\packages_imported\ktor-ktor-client-core\1.3.0-beta-1'
@ .._imported/ktor-ktor-client-core/1.3.0-beta-1/ktor-ktor-client-core.js
@ ./kotlin/gaia.js
@ multi ./kotlin/gaia.js source-map-support/browser-source-map-support.js
ERROR in .._imported/ktor-ktor-io/1.3.0-beta-1/ktor-ktor-io.js
Module not found: Error: Can't resolve 'text-encoding' in 'C:\Users\Daan\code\gaia\build\js\packages_imported\ktor-ktor-io\1.3.0-beta-1'
@ .._imported/ktor-ktor-io/1.3.0-beta-1/ktor-ktor-io.js 20149:21-45 20217:21-45
@ .._imported/ktor-ktor-client-json/1.3.0-beta-1/ktor-ktor-client-json.js
@ ./kotlin/gaia.js
@ multi ./kotlin/gaia.js source-map-support/browser-source-map-support.js
To Reproduce
Steps to reproduce the behavior:
Add text-encoding manually:
sourceSets["main"].dependencies { // or sourceSets["jsMain"] on mpp
implementation(npm("text-encoding", "0.7.0"))
}
I too am getting similar errors from webpack,
WARNING in ./node_modules/ktor-ktor-client-core/ktor-ktor-client-core.js 12105:13-32
Critical dependency: the request of a dependency is an expression
function jsRequire(moduleName) {
try {
return require(moduleName); // line: 12105
} catch (cause) {
throw Error_init("Error loading module '" + moduleName + "': " + cause.toString());
}
}
text-encoding is now unmaintained: https://www.npmjs.com/package/text-encoding
I've run into the same problem here. I'm using 1.3.1 version of io.ktor:ktor-client-js. I've added npm dependencies:
implementation(npm("abort-controller"))
implementation(npm("text-encoding"))
So, I get this:
WARNING in /.../build/js/packages_imported/ktor-ktor-client-core/1.3.1/ktor-ktor-client-core.js 16700:13-32
Critical dependency: the request of a dependency is an expression
Anyways, it does work, but I have concerns if everything is OK really. Probably it's not.
Getting the same results. Its odd...All this text is red and it wasn't there until a moment ago when I added a bunch of multi platform dependencies.
I'm getting the same error in a multiplatform project when I try to add (and use) the io.ktor:ktor-client-websockets-js dependency. (Ktor version: 1.3.2)
WARNING in ./kotlin-dce/ktor-ktor-client-core.js 8273:13-32
Critical dependency: the request of a dependency is an expression
@ ./kotlin-dce/fileflow.js
@ multi ./kotlin-dce/fileflow.js
ERROR in ./kotlin-dce/ktor-ktor-client-core.js
Module not found: Error: Can't resolve 'abort-controller' in 'C:\Users\molin\Desktop\kt\fileflow\build\js\packages\fileflow\kotlin-dce'
@ ./kotlin-dce/ktor-ktor-client-core.js 8259:23-50
@ ./kotlin-dce/fileflow.js
@ multi ./kotlin-dce/fileflow.js
ERROR in ./kotlin-dce/ktor-ktor-io.js
Module not found: Error: Can't resolve 'text-encoding' in 'C:\Users\molin\Desktop\kt\fileflow\build\js\packages\fileflow\kotlin-dce'
@ ./kotlin-dce/ktor-ktor-io.js 6805:21-45 6815:21-45
@ ./kotlin-dce/ktor-ktor-client-core.js
@ ./kotlin-dce/fileflow.js
@ multi ./kotlin-dce/fileflow.js
Code in JS target:
//If commented out compilation error disappears (probably dependency gets optimized out?)
val client = HttpClient {
install(WebSockets)
}
I tried to manually add the missing dependencies as suggsted above like so:
implementation(npm("text-encoding", "0.7.0"))
implementation(npm("abort-controller", "3.0.0"))
//These additionals dependencies pop out after adding the ones above
implementation(npm("utf-8-validate", "5.0.2"))
implementation(npm("bufferutil", "4.0.1"))
implementation(npm("fs", "0.0.2"))
...then the task runs successfully but the generated JS is broken:
Uncaught TypeError: b is not a function
at Object.l (fileflow.js:39)
at Object.<anonymous> (fileflow.js:39)
at n (fileflow.js:1)
at Object.<anonymous> (fileflow.js:39)
at n (fileflow.js:1)
at Object.<anonymous> (fileflow.js:39)
at n (fileflow.js:1)
at Object.<anonymous> (fileflow.js:39)
at n (fileflow.js:1)
at fileflow.js:1
EDIT: nevermind the websocket dependency, does the same even with just the standard ktor-client-js
I did manage to eliminate all these messages, but I do not fully recall how. I think the reasons were different for different packages but it usually came down to what one would expect, can't find the dependency where intellij thinks it should be. Here are a few suggestions
This might be helpful to someone having runtime problem Uncaught TypeError: b is not a function : it can be solved like so https://kotlinlang.org/docs/reference/javascript-dce.html#known-issue-dce-and-ktor.
CC @MMauro94 please see if it resolves the issue for you.
@edvorg Yep, that fixed it! Many thanks! I was able to perform a simple hello world with web sockets.
My build.gradle now looks like this:
kotlin {
js {
browser {
dceTask {
keep("ktor-ktor-io.\$\$importsForInline\$\$.ktor-ktor-io.io.ktor.utils.io")
}
}
}
//...
sourceSets {
//...
jsMain {
dependencies {
implementation kotlin('stdlib-js')
implementation "io.ktor:ktor-client-js:$ktor_version"
implementation "io.ktor:ktor-client-websockets-js:$ktor_version"
implementation(npm("text-encoding", "0.7.0"))
implementation(npm("abort-controller", "3.0.0"))
}
}
}
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Most helpful comment
@edvorg Yep, that fixed it! Many thanks! I was able to perform a simple hello world with web sockets.
My
build.gradlenow looks like this: