ktor: MPP JS client: Can't resolve 'text-encoding'
Ktor Version
1.1.2
Ktor Engine Used(client or server and name)
Ktor client with default engine
JVM Version, Operating System and Relevant Context
JDK 1.8, Windows, Kotlin JS
Feedback
We are using the ktor client in a multiplatform project (android, iOS and web). Starting with version 1.1.0 the build of the JS client fails with the following message:
ERROR in ./kotlinx-io.js
Module not found: Error: Can't resolve 'text-encoding' in '<mypath>\kotlinmultiplatform\web\build\kotlin-js-min\main'
@ ./kotlinx-io.js 5309:21-45 5320:21-45
@ ./ktor-utils.js
@ ./web.js
If I manually add text-encoding
as a npm-dependeny, it works.
If I list the npm dependency tree with the previous working ktor version 1.0.1 I get:
+-- kotlinx-io@0.1.4 -> <mypath>\kotlinmultiplatform\web\build\node_modules_imported\kotlinx-io extraneous
+-- kotlinx-io-js@0.1.1 -> <mypath>\kotlinmultiplatform\web\build\node_modules_imported\kotlinx-io-js
| +-- kotlin@1.3.10
| +-- kotlin-test@1.3.10
| | `-- kotlin@1.3.10 deduped
| +-- kotlinx-atomicfu@0.11.12 -> <mypath>\kotlinmultiplatform\web\build\node_modules_imported\kotlinx-atomicfu deduped
| `-- text-encoding@0.7.0
If I list the npm dependency tree with a ktor version >= 1.1.0 the kotlinx-io-js
(and of course text-encoding
) is missing
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 21 (8 by maintainers)
Commits related to this issue
- text-encoding added to npm install. workaround for https://github.com/ktorio/ktor/issues/961 — committed to thebehera/mqtt by thebehera 5 years ago
To fix this, I’ve added the following dependencies to my Gradle build:
This fixed the issue for me!
see https://github.com/Kotlin/kotlinx-io/issues/57 for my current work around
I’m also getting this error for 1.2.5 and 1.3.0-beta-1. Would really appreciate a fix as it’s holding up project development
I am getting the same error on Ktor 1.2.5 and 1.3.0-beta1:
For everyone who is struggling with this issue I have another solution which suits my needs better than adding the dependencies to build.gradle.kts.
I have a full-stack multiplatform project, JVM and Browser targets for now. The dependency solution proposed by @MrPowerGamerBR worked for me as well, but that puts about 700 KB of code into my distribution output. That’s a lot.
So, I removed the dependencies and solved the problem by creating a “webpack.config.d” directory in my projet root and putting an “external.js” file into it with the following content.
This might not work for everyone as you might actually need text-encodings but for me they are mostly pointless as I use code points instead of UTF-8. A very good article about the difference: What every JavaScript developer should know about Unicode
Now also getting this on 1.3.2: