Hi everyone, I’m creating JS modules from multipla...
# javascript
e
Hi everyone, I’m creating JS modules from multiplatform projects using the kotlin-frontend-plugin. I have module2 depending on module1. When building module2, node_modules_imported includes module1, kotlin (as node package, with a generated package.json file), etc. But inside module1, there is another level of node_modules that also includes kotlin (as an isolated .js file, without package.json). I think this generates
w: Module "kotlin" is defined in more than one file
warnings. Is there a way to avoid that? Can I make npm aware of the fact that both packages depend on kotlin and it should only be included once? Thanks!
It seems I had some naming problem. The gradle project’s name should be the same as the node module so it produces {module-name}.js files and is recognized by the plugin and the package manager. This also ensures require(‘module-name’) works properly in all generated JS files.
g
I was with a similar problem, it looks like if you define this kind of code in both modules it works:
Copy code
js {
        configure(listOf(compilations["main"], compilations["test"])) {
            tasks.getByName(compileKotlinTaskName) {
                kotlinOptions {
//                    languageVersion = "1.3"
                    metaInfo = true
                    sourceMap = true
                    sourceMapEmbedSources = "always"
                    moduleKind = "umd"
                }
            }
        }

        configure(listOf(compilations["main"])) {
            tasks.getByName(compileKotlinTaskName) {
                kotlinOptions {
                    outputFile = "${project.buildDir.path}/classes/kotlin/js/main/somePrefix-${project.name}.js"
                    main = "call"
                }
            }
        }
    }
where
somePrefix
is not really needed, but if you would like to name your module react, for example, your are going to need this.
At least this worked for me