It seems that source mapping doesn't work properly...
# javascript
i
It seems that source mapping doesn't work properly for now, isn't it? Is it known problem? It seems, that it can be fixed, using
Copy code
compileKotlinJs {
    kotlinOptions {
        sourceMapEmbedSources = "always"
    }
}
But I think, it should be more elegant
d
I think you're classifying something that is disabled as a bug, and the configuration to enable it as a fix. I think that's incorrect.
i
@Dico it's possible, but there is sourceMaps property (with default true value) in new 1.3.40 dsl, that generate source maps, and these source maps are unusable in browser (via webpack) for example. I expect, that I need configure this option only once to work with it. But now there is duplication of source map configuration with compiler option. I believe it can be easier. In addition, I am not sure, that inlining sources is the only option to generate valid source maps. I don't classify it as a bug, I only ask opinion about this situation, and want to know some plans about it.
d
Well now you added the context that is needed. Good.
r
Seems like there is some improvement could have been done. Since the new K/JS gradle plugin is still under development could you please file an issue about this to make sure we won’t miss it in future releases.
i
@Roman Artemev [JB] thanks for feedback and hard work!
🙏 1
l
@Ilya Goncharov [JB] Once you open the issue (maybe you already did), could you link it there please?
i
@Roman Artemev [JB] @louiscad done https://youtrack.jetbrains.com/issue/KT-32319
👍 1
s
@Ilya Goncharov [JB] Source maps should work in nodejs and webpack. It is not supported in karma stack traces yet: https://youtrack.jetbrains.com/issue/KT-31478
source-map-loader
webpack plugin should load source maps from corresponding
.js.map
files, so
sourceMapEmbedSources = "always"
is not required.
source-map-loader
should be configured by default. Please show your
webpack.config.js
in
build/js/packages/<compilation name>
folder. This code should do this job:
Copy code
// source maps
config.module.rules.push({
        test: /\.js$/,
        use: ["source-map-loader"],
        enforce: "pre"
});
config.module.rules.push({test: /\.js$/, use: ['source-map-loader'], enforce: 'pre'});
config.devtool = 'eval-source-map';

// source maps runtime
if (!config.entry) config.entry = [];
config.entry.push('source-map-support/browser-source-map-support.js');
i
@snrostov There is block related with source maps in webpack.config.js
Copy code
// source maps
config.module.rules.push({
        test: /\.js$/,
        use: ["source-map-loader"],
        enforce: "pre"
});
config.module.rules.push({test: /\.js$/, use: ['source-map-loader'], enforce: 'pre'});
config.devtool = 'eval-source-map';

// source maps runtime
if (!config.entry) config.entry = [];
config.entry.push('source-map-support/browser-source-map-support.js');
But when I run application, I can find my source files, but it has empty content I guess, it is due to output source maps It has empty "names" field, and mapping doen't work If I use sourceMapEmbedSources, it fills "sourcesContent" field If it matters, it is reproduced on windows
s
This looks like a bug indeed.
source-map-loader
webpack plugin should load source contents from source files by relative urls from source maps, but fails to do it for some reason. Will fix, thanks for report.
Looks like issue in
source-map-loader
webpack plugin. It loads source contents only when sourcesContent is empty or sourcesContent.length < sources.length. But in your case we have non empty sourcesContent with some nulls. source-map-loader doesn’t support this case.
I’ll send PR to
source-map-loader
.
As a workaround you can replace
source-map-loader/index.js
with this file