From Gradle

To select module system when compiling via Gradle, you should set moduleKind property, i.e.

compileKotlin2Js.kotlinOptions.moduleKind = "commonjs"

Available values are similar to Maven.

@JsModule annotation

To tell Kotlin that an external class, package, function or property is a JavaScript module, you can use @JsModule
annotation. Consider you have the following CommonJS module called "hello":

module.exports.sayHello = function(name) { alert("Hello, " + name); }

You should declare it like this in Kotlin:

@JsModule("hello")
external fun sayHello(name: String)

Applying @JsModule to packages

Some JavaScript libraries export packages (namespaces) instead of functions and classes.
In terms of JavaScript, it's an object that has members that are classes, functions and properties.
Importing these packages as Kotlin objects often looks unnatural.
The compiler allows to map imported JavaScript packages to Kotlin packages, using the following notation:

Importing deeper package hierarchies

In the previous example the JavaScript module exports a single package.
However, some JavaScript libraries export multiple packages from within a module.
This case is also supported by Kotlin, though you have to declare a new .kt file for each package you import.

@JsNonModule annotation

When a declaration has @JsModule, you can't use it from Kotlin code when you don't compile it to a JavaScript module.
Usually, developers distribute their libraries both as JavaScript modules and downloadable .js files that you
can copy to project's static resources and include via <script> element. To tell Kotlin that it's ok
to use a @JsModule declaration from non-module environment, you should put @JsNonModule declaration. For example,
given JavaScript code:

Notes

Kotlin is distributed with kotlin.js standard library as a single file, which is itself compiled as an UMD module, so
you can use it with any module system described above. Also it is available on NPM as kotlin package