Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot find module 'abort-controller' - REST call with JS #1822

Closed
FabianRohr opened this issue Apr 24, 2020 · 2 comments
Closed

Error: Cannot find module 'abort-controller' - REST call with JS #1822

FabianRohr opened this issue Apr 24, 2020 · 2 comments
Assignees
Labels

Comments

@FabianRohr
Copy link

FabianRohr commented Apr 24, 2020

Ktor Version and Engine Used (client or server and name)
ktor 1.3.0

Describe the bug
When performing a simple get request via the compiled JS code in a Kotlin multiplatform project using ktor, the following error is thrown:

(node:46932) UnhandledPromiseRejectionWarning: Error: Cannot find module 'abort-controller'
Require stack:
- /example-js/node_modules/ktor-ktor-client-core.js
- /example-js/node_modules/ktor-ktor-client-auth.js
- /example-js/node_modules/common.js
- /testRest.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at AbortController_0 (/example-js/node_modules/ktor-ktor-client-core.js:15169:24)
    at /example-js/node_modules/ktor-ktor-client-core.js:15106:20
    at /example-js/node_modules/ktor-ktor-client-core.js:15081:3
    at Coroutine$commonFetch.doResume (/example-js/node_modules/ktor-ktor-client-core.js:15136:116)
    at commonFetch (/example-js/node_modules/ktor-ktor-client-core.js:15164:23)
    at Coroutine$execute_dkgphz$.doResume (/example-js/node_modules/ktor-ktor-client-core.js:14513:25)

To Reproduce
Setup a Kotlin multiplatform project so that when you build via gradle, Kotlin generates the node_modules folder with your JS code including kotlin.js and common.js via the assembleJs gradle task. Then try to perform a simple get request using the ktor client like so:

test.kt in common/src/jsMain/kotlin/com.myApp/test.kt:

suspend fun getGoogle(): String {
    val client = HttpClient()
    return client.get<String>("https://www.google.de")
}

fun returnPromise(): Promise<String> = //or Promise<Unit> for voids
        GlobalScope.promise {
            getGoogle() // return a String
        }

testRest.js in example-js/:

const common = require("./node_modules/common")
console.log(common.returnPromise())

Also, when I add the actual abort-controller manually via npm, I just get another error about it missing another module, so I gave up at that point.

Expected behavior
Perform the get request and return the content of the requested web page.

@FabianRohr FabianRohr added the bug label Apr 24, 2020
@e5l e5l self-assigned this Apr 28, 2020
@SebastianAigner
Copy link
Contributor

SebastianAigner commented May 12, 2020

Hey @FabianRohr! There is currently a known issue regarding transitive dependencies that we hope to address soon. In the meantime, the workaround is indeed to add NPM dependencies directly to your build file.
Check out this sample Gradle build file, which should contain all dependencies you need to get Ktor clients running in Kotlin/JS: https://github.com/kotlin-hands-on/jvm-js-fullstack/blob/master/build.gradle.kts#L72

@oleg-larshin
Copy link

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants