How to use node_modules within electron


Using electron in combination with Angular2, Typescript and Electron I am try to find out how to use a node module package installed via npm.
The current problem is that I have to specify the location of the module like var test = require('./node_modules/xyz/lib/xyz.js'). But then electron does not find the dependencies of xyz, which are located within ./node_modules/xyz/node_modules/yyy and complains ./yyy.js can not be found.

The electron app structure

├── config.js  
├── index.html  
├── main.js  
├── node_modules  
├── package.json  
└── app.js  -> (var test = require('./node_modules/xyz/lib/xyz.js')


You don’t have to point the node_modules directory directly, but instead just require the package name: require('xyz') (or require('xyz/lib/xyz.js') if you need a specific file). Node will then search in node_modules when it can’t find the module locally.


Turns out that I used npm to install modules, but Angular2 depends on JSPM.
when installing modules with jspm install npm:xyz then I can require modules in electron like require(‘xyz’) .


Also thinking about adding Angular2 to the mix. However, isn’t it so that angular2 packages can be installed using npm just as well? To resolve them angular2 uses systemjs, which is universal and should be able to load commonjs style modules as well, no?