Kotlin / kotlin-frontend-plugin

Gradle Kotlin (http://kotlinlang.org) plugin for frontend development
Apache License 2.0
561 stars 69 forks source link

HMR not working correctly with Kotlin >= 1.3.20 #140

Open rjaros opened 5 years ago

rjaros commented 5 years ago

Since Kotlin version 1.3.20 HMR feature doesn't work correctly. The command ./gradlew -t run fails to rebuild the project after any change in the source code with an error like this:

ℹ 「wdm」: Compiling...
✖ 「wdm」: 
ERROR in ./frontend-only.js
Module build failed: Error: ENOENT: no such file or directory, open '/home/rjaros/git/github/kotlin-frontend-plugin/examples/frontend-only/build/js/frontend-only.js'
 @ multi webpack-dev-server/client?http://localhost:8088/ webpack/hot/dev-server ./frontend-only main[2]
ℹ 「wdm」: Failed to compile.

Similar error is displayed in the browser console window:

[HMR] Checking for updates on the server...
VM1602 log.js:26 [HMR] Cannot apply update. Need to do a full reload!
VM1602 log.js:26 [HMR] Error: Module build failed: Error: ENOENT: no such file or directory, open '/home/rjaros/git/github/kotlin-frontend-plugin/examples/frontend-only/build/js/frontend-only.js'
    at eval (webpack:///./frontend-only.js?:1:7)
    at Object../frontend-only.js (http://localhost:8088/main.f36273106d42fe3ef207.hot-update.js:16:1)
    at __webpack_require__ (http://localhost:8088/main.bundle.js:724:30)
    at hotApply (http://localhost:8088/main.bundle.js:657:14)
    at http://localhost:8088/main.bundle.js:314:22

There are some conditions to see this error:

The official "frontend-only" example can be used to reproduce this error after making the above changes in the build.gradle file.

Looking up the changelog for Kotlin 1.3.20 I've noticed this change: "KT-28842 Enable JS IC by default", which looks suspiciously, but disabling IC with kotlin.incremental.js=false doesn't solve the problem.

wem commented 5 years ago

I did not dive into, but the EOENT failure sound like a problem i got. I also never did use HMR, but may this workaround helps: https://discuss.kotlinlang.org/t/kotlin-js-incremental-compilation/11380

I hope it helps

rjaros commented 5 years ago

Thanks. I can confirm that both disabling incremental compilation and additional webpack configuration from https://discuss.kotlinlang.org/t/kotlin-js-incremental-compilation/11380/2 fixes the problem.