2

I am working on a project using kotlinjs for nodejs and I start to learn coroutines and integrate them into my code to say goodbye to the callback hell.

I managed to get coroutines working, my code can be compiled and executed, everything seems fine.

...except: The IDE still shows me errors. It seems to be confused by the additional libraries I added in order to get coroutines running.

I am currently fiddling around with the library dependencies, sometimes some errors go away, but then some code gets red which was okay before...

This is what I see:

Case 1:

module dependencies in the first case code in the first case

Cannot access class 'kotlinx.coroutines.experimental.CoroutineContext'. Check your module classpath for missing or conflicting dependencies

Case 2:

module dependencies in the second case code in the second case

Unresolved reference: JsModule

Modifier 'external' is not applicable to 'class'

You see, launch is recognized when I add the stdlib, but then the IDE complains with the other two errors.

Again, please note: In both cases, actual compilation is successful!

I am using IntelliJ 2018.1 with Kotlin Plugin 1.2.41.

Community
  • 1
  • 1
  • 1
    Looks like a bug. Try with 2018.2 version from https://www.jetbrains.com/idea/nextversion If error remains, please report at https://youtrack.jetbrains.com/issues/KT with sample project to reproduce. – Andrey May 23 '18 at 14:21
  • Thank you, I tried it ...but same behavior. I will report it to JetBrains. – Christoph Berghuber May 24 '18 at 06:58
  • Could you please share your project? And of course please report an issue. – bashor May 24 '18 at 16:17
  • Use only "...-core-js" version -- remove 2nd library "...-core". Don't use "kotlin-stdlib" for Kotlin/JS, use "kotlin-stdlib-js" instead (it's part of KotlinJavaScript) – bashor May 24 '18 at 16:21

1 Answers1

0

Thanks to Alexander Chernikov at youtrack.jetbrains I could resolve my problem.

I cite his explanation:

The issue is that JavaScript libraries should be marked with special attribute to be recognized. When they are imported from pom.xml or build.gradle, this mark is set, so the feature works. In your project they are not marked.

At the moment, to correct the libs manually, please open .idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_js_1_2_41.xml and .idea/libraries/org_jetbrains_kotlinx_kotlinx_coroutines_core_js_0_22_5.xml. In both files find type="repository" and replace it with type="kotlin.js". Make sure IDEA sees the change. (You can exit IDEA, make the change and restart.)

Then you can keep only these two libs in dependencies. The editor should work.

Here is the issue link: https://youtrack.jetbrains.com/issue/KT-24575

There I have also attached a sample project with the problem.