The Javascript output of the Kotlin compiler - the way I have it set up, anyway - is one file for Kotlin's standard library and one for the compiled form of all of my Kotlin files. The file with the standard library in it starts out by creating a variable `Kotlin` in the global scope and then it initializes it and assigns it to module.exports so it is available both when included in a web page with the `script` tag and when using the `require()` function in Node. The compiled form of my code, however, is just an immediately invoked function expression that expects `Kotlin` to already be in the global scope. Node is specifically designed so that separate files don't pollute the global scope, though, so there is no obvious way to make this file work with Node. The best I can think of is to create my own build script to invoke the compiler and then modify its output, which would partially defeat the purpose of using such an expensive IDE.
I need solutions that don’t involve rewriting my entire project in Kotlin - though I’m considering doing this eventually, it’s not a realistic proposition right now because that would involve troubleshooting an entire project all at once while having basically no automated tests passing for much of the time it takes to do this. I also won’t simply use the JVM as my target because that requires a complete rewrite and I’d have to find or write replacements for all of the third party libraries I’m using.
In settings, in
Build, Execution and Deployment section, under Compiler / Kotlin Compiler, there is output file prefix and postfix settings. These are paths to files with text that will be prepended and appended to compiler's output. Does it help in your particular case?
I think at this point Kotlin Js has been evolved much and it is ready for Node.js application.
you can now even write your node.js app entirely with Kotlin.
as a proof of concept I created Node.js Express.js project using Kotlin
Why do I need gradle in my NodeJS Kotlin project, when any other language lives just fine with npm alone?
Please excise Kotlin from the dying Java environment, make it as widespread as TypeScript is for Frontend and Backend development in NodeJs. Have you ever tried to build something like a Backend with a GraphQL API using GraphQL and Spring libs in Java/Kotlin? It is horrible, clunky, and full of undocumented and deprecated code.
Please bring Kotlin to JS without any Java-related gimmicks like gradles, JVMs, Springs, and such. Don’t let Kotlin die!
Why do I need gradle in my NodeJS Kotlin project, when any other language lives just fine with npm alone?
You could originally create npm-only Kotlin projects (at least when using create-react-kotlin-app). I assume it was abandoned because Kotlin integrates so well with Gradle already, that it made more sense to bring better npm support to Gradle than better Kotlin support to npm. (Additionally, multiplatform would become quite a busy mess of different build tools if we ended up with the most popular build tool for each target).