Is there some trick to get sourcemaps working with...
# javascript
j
Is there some trick to get sourcemaps working with kotlin js and the multiplatform plugin? I set sourceMaps to true in the browser runTask, source map files get generated but I see no sign of the browser doing anything with them. Also the .map files seem unavailable via the dev server (I get a 404 when I request them). What am I missing? I'm using the fritz2 framework.
s
You shouldn’t need to modify your Gradle file for source maps to be working. I’ve just tried a minimal example with the latest version of Chrome, Kotlin MPP 1.4.21 w/ Kotlin/JS (non-IR), and the latest version of Fritz2, and source maps work out of the box for me. Running via
jsBrowserDevelopmentRun
Gradle task.
n
I’ve also had lots of issues with this. They work for the current app, but not well for any framework. I have issues where only a random subset of Doodle files have working maps. And it usually includes those that have been edited. All others show up via relative url and the browser complains that the map url is invalid. Super frustrating, since i usually have to drop random printlns to step into a file. This is with 1.4.21 (non-IR), and has been the case for previous versions as well.
You can see that there are 2 ways source-maps are produced. The absolute path versions (used for the app, and random subset of framework files) work. While those under the relative path (relative to the app root) do not. I've only seen Doodle's maps generate using the relative approach. I'm not sure if there's some config somewhere I'm missing. Doodle is itself a MPP project. Here's a link to its gradle file.
a
sourceMaps are working for you guys?
j
Clearly something is different on my setup; trying to figure out what.
n
The issue I mention was also reported a year ago here: https://discuss.kotlinlang.org/t/kotlin-mpp-webpack-sourcemap-issue-on-included-dependencies/17236. @Sebastian Aigner, any word on how to fix this?
i
In dev mode, source maps are not represented as separate file, but included into finaly js script Usually you can go to Sources tab in browser, and navigate to source file (for example in Chrome it is Ctrl+O and the type App.kt)
a
With IR?
i
No, IR for now doesn’t generate source maps unfortunately
n
This works for app code; but the issue is with libraries used by the app. See my comments, or the linked post for more details.
This is Doodle (https://nacular.github.io/doodle) in my case, which is a MPP set of libs.
i
Thanks, seems that I have reproduced issue. Indeed there is problem because in source maps of Kodein there is link on file, but content of this file is not reproduced in project. That’s why 404 error. BTW, in Doodle there is no source maps in maven module
n
That’s by design. They should be present for non-release builds though (but these are the builds I see issues with). This is what my build script does: js { val releaseBuild = project.hasProperty("release") compilations.all { kotlinOptions { moduleKind = "umd" sourceMap = !releaseBuild if (sourceMap) { sourceMapEmbedSources = "always" } freeCompilerArgs = listOf("-Xuse-experimental=kotlin.ExperimentalUnsignedTypes") } } browser { testTask { enabled = false } } }