# Node.js proper module export

**URL:** <https://discuss.kotlinlang.org/t/node-js-proper-module-export/5040>\
**Category:** JavaScript\
**Created:** [October 19, 2017, 1:40pm UTC](https://discuss.kotlinlang.org/t/node-js-proper-module-export/5040 "2017-10-19T13:40:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vsazel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/vsazel/32/1491_2.png) [@vsazel](https://discuss.kotlinlang.org/u/vsazel)\
**Post date:** [October 19, 2017, 1:40pm UTC](https://discuss.kotlinlang.org/t/node-js-proper-module-export/5040/1 "2017-10-19T13:40:39Z")

</div>

Hi,

I’m currently updating my multiplatform Hello Kotlin project  
[https://github.com/wojta/hello-kotlin/tree/kotlin-1.2-beta](https://github.com/wojta/hello-kotlin/tree/kotlin-1.2-beta) with new multiplatform support Kotlin introduced. There are not many problems related to that.

But there is another problem not related to multiplatform support. I have project module called **hello\_js\_node\_app** and it’s supposed to be run as Node.js app. It has one dependency on other kotlin2Js module called **hello\_lib\_js**. I need to export properly .js files from jars of both modules to have it imported by _require()_ module.  
So far I have this [build.gradle](https://github.com/wojta/hello-kotlin/blob/kotlin-1.2-beta/hello_js_node_app/build.gradle) and **assembleJs** task expands everything to the _node\_modules_.

node\_modules look like this: [https://drive.google.com/file/d/0B-k1pGbOW-o3VmNiVXZwNEZCVXc/preview](https://drive.google.com/file/d/0B-k1pGbOW-o3VmNiVXZwNEZCVXc/preview)

Problem is that when I execute `node ./app.js`, it can’t find kotlin module dependecy. I’m not sure about Node module directory structure, but I have not deep knowledge of Node.

> **node error message**
>
> ```
> vsazel@vsazel-thinkpad ~/git/ghdrive/experiments/hello-kotlin/hello_js_node_app $ node ./app.js 
> /home/vsazel/git/ghdrive/experiments/hello-kotlin/hello_js_node_app/node_modules/hello_lib_js.js:2
> throw new Error("Error loading module 'hello_lib_js'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'hello_lib_js'.");
> ^
> 
> Error: Error loading module 'hello_lib_js'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'hello_lib_js'.
> at Object.<anonymous> (/home/vsazel/git/ghdrive/experiments/hello-kotlin/hello_js_node_app/node_modules/hello_lib_js.js:2:9)
> at Module._compile (module.js:409:26)
> at Object.Module._extensions..js (module.js:416:10)
> at Module.load (module.js:343:32)
> at Function.Module._load (module.js:300:12)
> at Module.require (module.js:353:17)
> at require (internal/module.js:12:17)
> at Object.<anonymous> (/home/vsazel/git/ghdrive/experiments/hello-kotlin/hello_js_node_app/node_modules/hello_js_node_app.js:24:38)
> at Module._compile (module.js:409:26)
> at Object.Module._extensions..js (module.js:416:10)
> 
> ```

So is there some more convinent or correct way to export Kotlin modules as node modules?

Thanks

---

<div class="post-metadata">

**Author:** ![Alexey.Andreev](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Alexey.Andreev](https://discuss.kotlinlang.org/u/Alexey.Andreev)\
**Post date:** [October 19, 2017, 4:30pm UTC](https://discuss.kotlinlang.org/t/node-js-proper-module-export/5040/2 "2017-10-19T16:30:05Z")

</div>

Looks like for some reason `moduleKind` property did not apply properly. Did you set up `moduleKind=commonjs` for hello\_lib build script? Can you provide more information? Perhaps, share your project?

---

<div class="post-metadata">

**Author:** ![Alexey.Andreev](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Alexey.Andreev](https://discuss.kotlinlang.org/u/Alexey.Andreev)\
**Post date:** [October 19, 2017, 4:33pm UTC](https://discuss.kotlinlang.org/t/node-js-proper-module-export/5040/3 "2017-10-19T16:33:20Z")

</div>

Ah, I just realized that you provided link to whole project. Yes, I could not find `moduleKind` in `hello_lib_js`. Please add it the way similar you did in `hello_js_node_app`.

---

<div class="post-metadata">

**Author:** ![vsazel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/vsazel/32/1491_2.png) [@vsazel](https://discuss.kotlinlang.org/u/vsazel)\
**Post date:** [October 19, 2017, 11:26pm UTC](https://discuss.kotlinlang.org/t/node-js-proper-module-export/5040/4 "2017-10-19T23:26:05Z")

</div>

Thanks for pointing me to the right direction. I managed to get node modules working. I need only now to get it working with the client-side JS again. Maybe it will help using browserify or something like that.

---

<div class="post-metadata">

**Author:** ![Alexey.Andreev](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Alexey.Andreev](https://discuss.kotlinlang.org/u/Alexey.Andreev)\
**Post date:** [October 20, 2017, 8:29am UTC](https://discuss.kotlinlang.org/t/node-js-proper-module-export/5040/5 "2017-10-20T08:29:13Z")

</div>

Yes, you can use browserify or webpack for this purpose. Another way is to use “umd” as a module kind, which is supported by both browsers and node.
