Include packages from bower


What is the best way to include a bower package into my kotlin js project?

So far I’m only including external js libs that are distributed as single js files and this works fine. However, now I want to integrate the zib library pako. Pako is only available on bower and I can’t figure out how to integrate it into my project. I tried to simply use the pako.js that I downloaded with bower but this does not work. Is there a way to extract a bower package into a single file?

Update: I managed to load the pako.js from bower into a dummy html project using RequireJS. However, when I try to include the require.js file in my kotlin test I get the error:
Error: Mismatched anonymous define() module: function (_, Kotlin)
I think this is because kotlin interferes with require js. Any idea how to use require.js in a kotlin test (Karma/Mocha)?


Pako is only available on bower

Is this a different thing?

Error: Mismatched anonymous define() module: function (_, Kotlin)

Looks like this. Most likely this is due to the fact that we use anonymous AMD module definitions for portability reasons. That gives developers more flexibility, but it also requires some more configuration. Please refer to Kotlin AMD tutorial and require.js configuration options

Kotlin/JS should work with require.js just fine. That being said testing AMD modules is notoriously tricky, especially if you are trying to mix AMD and CommonJS together.


Thanks that helped. Now, I’m loading all modules and tests using requirejs. The only remaining problem is that karma does not wait for any tests / it is not aware that the tests are loaded asynchronously. This is only a problem when running karmaRun gradle task. When I debug my test in the browser I can see from the console output that the tests are executing. Is there a way to tell karma that the tests are loaded async and that it should wait for those tests?

Here is some pseudo code from my build.gradle file in case somebody has the same problem:

karma {
    dependencies(['mocha', 'karma-requirejs'])
    frameworks = ['mocha', 'requirejs']
    browsers = ['Firefox']

    files = [       
            // include require js
            // load the tests:

            // serve files but do not load them (they are loaded in main.js using requirejs)
            [pattern: "../path/to/pako.min.js", included: false],
            [pattern: "$libDir/*.js", included: false],
            [pattern: compileOutput, included: false],
            [pattern: testOutput, included: false],

            [pattern: "${projectDir}/build/classes/main/", included: false],
            [pattern: "${projectDir}/build/classes/test/", included: false],

and the test_main.js

    // path where all main libs are located, e.g. kotlin.js
    // "base" is the karma root directory as the browser sees it (also look at
    // the debug.html file in the browser debugger to see all served files)
    baseUrl: '/base/myLibJS/build/lib',

    paths: { // paths are relative to test_main.js
        'pako': '../relative/path/pako.min',
        'myLibJS': '../relative/path/build/classes/main/myLibJS',
        'myLibJS_test': '../relative/path/build/classes/test/myLibJS_test',

    deps: ['pako', 'myLibJS_test'],

    // start tests when done
    callback: window.__karma__.start


I’ve just found Karma docs on how to use it with require.js

Your solution looks pretty close to what they are suggesting, except for a few details. Could you try:

  • moving "main.js" to the last position in files array
  • adding a 'requirejs' framework adapter (doesn’t look like it’s doing anything vital though)

and see if any of it helps. If not I’ll try reproducing.

My hunch is that you are telling Karma to load the main.js before any of the test files, and that causes problems.


Thanks again! Just including requirejs as a dependency and as a framework does the trick. I updated my previous post and added the changes there.


Congrats on making that work! =)